Created
June 11, 2016 15:01
-
-
Save dasibre/4553ff15d1fd14ad1fab3d07b72f6e9c to your computer and use it in GitHub Desktop.
rspec idioms for cleaner tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Thing do | |
def given_thing_with(options) | |
yield Thing.new do |thing| | |
thing.set_status(options[:status]) | |
end | |
end | |
it "should do something when ok" do | |
given_thing_with(:status => 'ok') do |thing| | |
thing.do_fancy_stuff(1, true, :move => 'left', :obstacles => nil) | |
... | |
end | |
end | |
it "should do something else when not so good" do | |
given_thing_with(:status => 'not so good') do |thing| | |
thing.do_fancy_stuff(1, true, :move => 'left', :obstacles => nil) | |
... | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sort of indirection can make under- standing failures quite painful when overused.