In the test below, the Bar and Baz blocks contain identical specs.
Leaving aside why such repetition was necessary in the first place, I'm wondering how one could dry this up.
I tried turning the blocks into objects and calling them under Bar and Baz, but possibly because I did not get the scopes right, I have not been able to make it work.
describe Foo do
describe Bar do
before(:each) do
prepare
end
it "should do something" do
true
end
it "should do something else" do
true
end
end
describe Baz do
before(:each) do
prepare_something_else
end
it "should do something" do
true
end
it "should do something else" do
true
end
end
end
you might want to create macros. here are some tutorials:
http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/
http://intridea.com/2009/5/15/make-it-so-with-rspec-macros?blog=company
http://railscasts.com/episodes/157-rspec-matchers-macros
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With