Created
July 6, 2012 07:22
-
-
Save udzura/3058640 to your computer and use it in GitHub Desktop.
smelling rspec
This file contains 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
require 'rspec' | |
# This smells | |
[[ 1, 2, 3], | |
[ 4, 8, 12], | |
[-2, 3, 1], | |
[ 0, 0, 0]].each do |a, b, c| | |
describe "#{a} + #{b}" do | |
subject { a + b } | |
it { should == c } | |
end | |
end | |
# I prefer this | |
shared_examples_for "plus" do |a, b, c| | |
describe "#{a} + #{b}" do | |
subject { a + b } | |
it { should == c } | |
end | |
end | |
describe do | |
it_behaves_like "plus", 1, 2, 3 | |
it_behaves_like "plus", 4, 8, 12 | |
it_behaves_like "plus", -2, 3, 1 | |
it_behaves_like "plus", 0, 0, 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment