Nested Example Groups
November 29th, 2007
Since rspec first appeared on the scene, users have been asking for nested example groups. Well it has finally arrived. RSpec 1.1.0 will ship with support for nesting, so you’ll be able to do things like this:
describe RSpec do
before(:each) do
@rspec = RSpec.new
end
describe "at release 1.0.8" do
before(:each) do
@rspec.version = "1.0.8"
end
it "should not support nested example groups" do
@rspec.should_not support_nested_example_groups
end
end
describe “at release 1.1.0″ do
before(:each) do
@rspec.version = “1.1.0″
end
it "should support nested example groups" do
@rspec.should support_nested_example_groups
end
end
end
This will output:
RSpec at release 1.0.8 - should not support nested example groupsRSpec at release 1.1.0 - should support nested example groups
If you’re using trunk, you can do this now with revision 3009 or later.
<p>Happy nesting!</p>


November 29th, 2007 at 3:58 am
This looks great. Very much appreciated.
November 29th, 2007 at 3:58 am
Whoah! Great feature! It’s going to make my controller examples more DRY!
November 29th, 2007 at 3:58 am
When is the next release 1.1.0?
November 29th, 2007 at 3:58 am
This really helps with organization. Thanks for this update David!
November 29th, 2007 at 3:58 am
Thank you very much! This is probably the feature I most wanted to help better organize my specs. Many of my specs have similar setup in the before block, and then diverge slightly. Previously I had been creating a module with setup methods, and them import it into every describe block, but this is going to show my intentions much more clearly.
November 29th, 2007 at 3:58 am
@CN – we’ll be doing a 1.1.0-RC1 within a week. We still have some work to do but we want to get it out the door.
November 29th, 2007 at 3:58 am
This is terrific. Any chance of getting the nesting to appear as indenting in the html report output? When we introduced rspec for acceptance-test-driven-development in the summer, the one thing that would have made our PM even happier would have been if the html report could have subsections indented, and sub-sub-sections doubly indented, so he could show the whole project’s rspec_report.html to the rest of the business and orient them in it more quickly.
November 29th, 2007 at 3:58 am
@Sean – our focus for business-facing reporting is on the story runner. Check out the prototype for the in-browser story runner/editor if you haven’t already
November 29th, 2007 at 3:58 am
Thank you so much David! This is a feature I’ve been waiting for!
November 29th, 2007 at 3:58 am
David, thanks for your reply I am a great fan of the tool. Turned our to be problems with ruby gems and not rspec in specific. Mongrel 1.1.1 is now also complaining when booting that some plugins cannot be found. looking forward for the release…