Yardspec
Note
This project is archived because I no longer actively use it, and there seems to be no recent activity from other users either. If you are still using it and would like to take over maintenance, please reach out to me.
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
endThe 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_examplesthen 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}"])