Skip to content

Instantly share code, notes, and snippets.

@SpringMT
Forked from udzura/it_smells_like_spec.rb
Created September 3, 2012 01:32
Show Gist options
  • Save SpringMT/3606103 to your computer and use it in GitHub Desktop.
Save SpringMT/3606103 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