Skip to content

Instantly share code, notes, and snippets.

@moro
Created September 19, 2012 02:31
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save moro/3747312 to your computer and use it in GitHub Desktop.
unit_test_spec.rb
class A
def foo(num)
%w[one two three][num - 1]
end
end
describe A do
describe "#foo" do
RSpec::Matchers.define :do_foo do |args|
match do |instance|
instance.foo(args) == @expectation
end
chain :to do |expectation|
@expectation = expectation
end
end
subject(:instance) { A.new }
it { should do_foo(1).to('one') }
it { should do_foo(2).to('two') }
it { should do_foo(3).to('three') }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment