Skip to content

Instantly share code, notes, and snippets.

@udzura
Created July 6, 2012 07:22
Show Gist options
  • Save udzura/3058640 to your computer and use it in GitHub Desktop.
Save udzura/3058640 to your computer and use it in GitHub Desktop.
smelling rspec
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