#129 √ resolved
Chad Humphries

[#15088] Nested behaviour descriptions

Reported by Chad Humphries | November 19th, 2007 @ 06:39 AM | in 1.1.0

This is a prerequisite to the nested example group story #127

class FooSpec < Spec::ExampleGroup
  describe Foo
end

class DoingThisSpec < FooSpec
  describe "doing this"
  it "should bar" {}
end

class DoingThatSpec < FooSpec
  describe "doing that"
  it "should bam" {}
end

Would generate something like:

Foo:
- doing this:
-- should bar
- doing that:
-- should bam

Comments and changes to this ticket

  • David Chelimsky

    David Chelimsky November 19th, 2007 @ 11:22 AM

    • → State changed from “new” to “open”
    • → Assigned user changed from “” to “Brian Takita”

    Brian - I'm pretty sure this is all done. Would you kindly close this ticket if you agree?

  • David Chelimsky

    David Chelimsky November 29th, 2007 @ 09:04 AM

    Got descriptions working correctly for nested example groups using the describe method, but it is not yet working w/ this class structure as of r3009.

  • Brian Takita

    Brian Takita December 8th, 2007 @ 12:27 PM

    As of r. 3092, all formatters except HtmlFormatter and TextmateFormatter support nested ExampleGroups.

    I'm unsure about how the html nesting will be done. I believe we agreed on

      tags.

  • Brian Takita
  • David Chelimsky
  • David Chelimsky

    David Chelimsky December 8th, 2007 @ 03:47 PM

    I'm not sure what you mean by "all formatters except HtmlFormatter and TextmateFormatter support nested ExampleGroups."

    When I run this:

    ruby bin/spec examples/pure/stack_spec_with_nested_example_groups.rb -fs
    

    I see this

    Stack (empty)
    - should be empty
    - should not be full
    - should add to the top when sent #push
    - should complain when sent #peek
    - should complain when sent #pop
    
    Stack (with one item)
    - should not be empty
    - should return the top item when sent #peek
    - should NOT remove the top item when sent #peek
    - should return the top item when sent #pop
    - should remove the top item when sent #pop
    - should not be full
    - should add to the top when sent #push
    
    Stack (with one item less than capacity)
    - should not be empty
    - should return the top item when sent #peek
    - should NOT remove the top item when sent #peek
    - should return the top item when sent #pop
    - should remove the top item when sent #pop
    - should not be full
    - should add to the top when sent #push
    
    Stack (full)
    - should be full
    - should not be empty
    - should return the top item when sent #peek
    - should NOT remove the top item when sent #peek
    - should return the top item when sent #pop
    - should remove the top item when sent #pop
    - should complain on #push
    
    Finished in 0.049715 seconds
    
    26 examples, 0 failures
    

    So the nested groups are supported, but the output is not nested at all.

    Currently, the html outputs a similar format:

    I'm inclined to leave this as/is. I think nesting the output would actually make things more complicated - especially if you start nesting at multiple layers. So I'm inclined to close this ticket as invalid, but I'll await other opinions before I do.

  • Brian Takita

    Brian Takita December 8th, 2007 @ 08:27 PM

    Thats strange.

    I see:

    Stack:

    • Stack (empty):

    -- should be empty

    -- should not be full

    -- should add to the top when sent #push

    -- should complain when sent #peek

    -- should complain when sent #pop

    Stack:

    • Stack (with one item):

    -- should not be empty

    -- should return the top item when sent #peek

    -- should NOT remove the top item when sent #peek

    -- should return the top item when sent #pop

    -- should remove the top item when sent #pop

    -- should not be full

    -- should add to the top when sent #push

    Stack:

    • Stack (with one item less than capacity):

    -- should not be empty

    -- should return the top item when sent #peek

    -- should NOT remove the top item when sent #peek

    -- should return the top item when sent #pop

    -- should remove the top item when sent #pop

    -- should not be full

    -- should add to the top when sent #push

    Stack:

    • Stack (full):

    -- should be full

    -- should not be empty

    -- should return the top item when sent #peek

    -- should NOT remove the top item when sent #peek

    -- should return the top item when sent #pop

    -- should remove the top item when sent #pop

    -- should complain on #push

    Shoulda separates its nested ExampleGroup descriptions with a space. I think that solution is easy to implement and better than showing only the last ExampleGroup description, in terms of being DRY.

  • David Chelimsky

    David Chelimsky December 8th, 2007 @ 08:41 PM

    That's what you see after the changes you just committed :)

    What I posted above was how things looked at revision 3084.

  • David Chelimsky

    David Chelimsky December 8th, 2007 @ 08:43 PM

    Brian and I just discussed this and Brian is working on changing the format back to outputting concatenated ExampleGroup descriptions with nested Example descriptions:

    Group
    - example
    - example
    - etc
    
  • Brian Takita

    Brian Takita December 8th, 2007 @ 10:17 PM

    • → State changed from “open” to “resolved”

    r. 3093

  • David Chelimsky

    David Chelimsky December 9th, 2007 @ 12:36 AM

    • → State changed from “resolved” to “open”

    I'm reopening this.

    Before the most recent changes I was able to do this:

    describe ScorecardController do
      describe "GET index" do
        it "should assign scoring domains" do
          ScoringDomain.stub!(:find_parents).and_return(
            scoring_domains = [Object.new]
          )
          get :index
          assigns[:scoring_domains].should equal(scoring_domains)
        end
        
        it "should assign all institutions" do
          Institution.stub!(:find).with(:all).and_return(
            institutions = [Object.new]
          )
          get :index
          assigns[:institutions].should equal(institutions)
        end
      end
    end
    

    Now it bails on the nested group saying:

    You have to declare the controller name in controller specs. For example:
                describe "The ExampleController" do
                controller_name "example" #invokes the ExampleController
                end
    

    So the nested group needs to return ScorecardController for the described_type

  • David Chelimsky

    David Chelimsky December 9th, 2007 @ 12:35 AM

    Also, this:

    describe Foo do
      describe "#bar" do
        it "should baz" do
        end
      end
    end
    

    should produce this

    Foo#bar
    - should baz
    

    It's back to adding a space between Foo and #bar. If the second part starts with '#' or '.', we don't put in the space. At least we didn't.

  • David Chelimsky

    David Chelimsky December 9th, 2007 @ 12:44 AM

    I added pending example for the described type getting passed down in rev3099.

  • David Chelimsky

    David Chelimsky December 9th, 2007 @ 12:52 AM

    • → Milestone changed from “” to “1.1.0”

    Tagging this to 1.1. This has to be right before we can release.

  • Brian Takita

    Brian Takita December 9th, 2007 @ 09:16 AM

    Fixed space before # and . in 3099

  • Brian Takita

    Brian Takita December 9th, 2007 @ 09:33 AM

    #described_type issue fixed in 3100.

  • Brian Takita

    Brian Takita December 9th, 2007 @ 09:46 AM

    • → State changed from “open” to “resolved”

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins

People watching this ticket

Attachments