Project

yardspec

0.01
No commit activity in last 3 years
No release in over 3 years
Use YARD examples as RSepc examples.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0
>= 0
 Project Readme

Yardspec

test

Run YARD as RSpec.

module Foo
  class Bar
    # @example returns "baz"
    #   expect(Foo::Bar.new.baz).to eq('baz')
    #
    # @example returns "bazbaz" for count 2
    #   expect(Foo::Bar.new.baz(count: 2)).to eq('bazbaz')
    #
    # @return [String]
    def baz(count: 1)
      'baz' * count
    end
  end
end

The code above is interpreted as follows:

$ bundle exec rspec

Foo::Bar#baz
  returns "baz"
  returns "bazbaz" for count 2

Finished in 0.00129 seconds (files took 0.087 seconds to load)
2 examples, 0 failures

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add yardspec

If bundler is not being used to manage dependencies, install the gem by executing:

gem install yardspec

Usage

Require "yardspec" and call Yardspec.define_examples as follows:

# spec/yard_spec.rb
require 'yardspec'

Yardspec.define_examples

then run entire test suite:

bundle exec rspec

or run this test file:

bundle exec rspec spec/yard_spec.rb

Path glob

Yardspec.define_examples takes optional path glob as an argument.

If nothing is specified, the default value of YARD is used.

Yardspec.define_examples(["{lib,app}/**/*.rb", "ext/**/*.{c,cc,cxx,cpp,rb}"])