Skip to content

Instantly share code, notes, and snippets.

@ngan
Created October 4, 2012 17:33
Show Gist options
  • Save ngan/3835153 to your computer and use it in GitHub Desktop.
Save ngan/3835153 to your computer and use it in GitHub Desktop.
shared_examples "a measurable object" do |measurement, measurement_methods|
measurement_methods.each do |measurement_method|
it "should return #{measurement} from ##{measurement_method}" do
subject.send(measurement_method).should == measurement
end
end
end
describe Array, "with 3 items" do
subject { [1, 2, 3] }
it_behaves_like "a measurable object", 3, [:size, :length]
end
describe String, "of 6 characters" do
subject { "FooBar" }
it_behaves_like "a measurable object", 6, [:size, :length]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment