Nested Example Groups 10

Posted by David Thu, 29 Nov 2007 08:58:18 GMT

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 groups

RSpec 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.

Happy nesting!

Comments

Leave a response

  1. Avatar
    Tom Ward Thu, 29 Nov 2007 10:56:39 GMT

    This looks great. Very much appreciated.

  2. Avatar
    Matthijs Langenberg Thu, 29 Nov 2007 12:39:19 GMT

    Whoah! Great feature! It’s going to make my controller examples more DRY!

  3. Avatar
    CN Thu, 29 Nov 2007 16:34:30 GMT

    When is the next release 1.1.0?

    I am retesting my applications with rails RC_2 now and there are lots of things to change. Is rspec compatible already with the release.

  4. Avatar
    Lance Carlson Thu, 29 Nov 2007 21:43:02 GMT

    This really helps with organization. Thanks for this update David!

  5. Avatar
    Dan Kubb Thu, 29 Nov 2007 21:58:03 GMT

    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.

  6. Avatar
    David Chelimsky Thu, 29 Nov 2007 22:41:46 GMT

    @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.

    In the mean time, the current trunk (3015) IS compatible w/ Rails 2.0.0-RC2.

    @Matthijs – sadly, it doesn’t work that well w/ controller examples. It will before the final 1.1.0 release, but not necessarily before the RC.

  7. Avatar
    Sean Miller Fri, 30 Nov 2007 05:34:11 GMT

    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.

  8. Avatar
    David Chelimsky Fri, 30 Nov 2007 06:44:19 GMT

    @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

    The addition of nesting is really a developer-friendly addition in that it supports DRYing up your examples, but it doesn’t really affect output yet.

    We may eventually support some different output that is more aligned w/ the story runner output, but that is very low on our priority list right now. In fact, it’s not even in the tracker – so feel free to add a feature request.

  9. Avatar
    Zach Dennis Fri, 30 Nov 2007 17:59:02 GMT

    Thank you so much David! This is a feature I’ve been waiting for!

  10. Avatar
    CN Fri, 30 Nov 2007 21:24:27 GMT

    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…

Comments