[rspec-devel] [ rspec-Feature Requests-10718 ] Add :locals hash to 'it_should_behave_like' method (SharedBehavior)

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 18 23:55:19 EST 2007


Feature Requests item #10718, was opened at 2007-05-09 10:36
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10718&group_id=797

Category: None
Group: None
Status: Open
Priority: 3
Submitted By: Chris Hoffman (hoffman_c)
Assigned to: Nobody (None)
Summary: Add :locals hash to 'it_should_behave_like' method (SharedBehavior)

Initial Comment:
It would be great if we could pass arbitrary variables into the shared behavior specs, for things such as differing controller actions.  Right now, I'm having to do the following:

before(:all) do
   @action = "foo"
end
it_should_behave_like "CRUD"

Instead, I could imagine something like the following, a la partial locals:

it_should_behave_like "CRUD", :locals => { :action => "foo" }

----------------------------------------------------------------------

Comment By: Chad Humphries (spicycode)
Date: 2007-11-18 23:55

Message:
Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/87-10718-add-locals-hash-to-it_should_behave_like-method-sharedbehavior#ticket-87-2

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-16 00:03

Message:
It happens implicitly. Calling #it_should_behave_like copies all the exampls from the shared behaviour into the current behaviour. Any local variables defined before(:each) example are available in each example.

----------------------------------------------------------------------

Comment By: Chris Hoffman (hoffman_c)
Date: 2007-05-09 11:19

Message:
how would @thing be assigned in the call to
it_should_behave_like in your example?  

I was imagining that a local 'thing' variable would get
assigned, perhaps with block locals.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-09 11:10

Message:
Interesting idea but there's a disconnect. Locals are actually slung over to another scope (the partial), whereas shared examples are all executed in the same scope as any non-shared examples. It's, conceptually, a different animal, that will surely lead to confusion when you start doing this:

describe Thing do
  before(:each) do
    @thing = Thing.new(:some_state)
  end
  
  it_should_behave_like "other things", :locals => { :thing => Thing.new(:some_other_state) }
  
  it "should do something unique" do
    @thing.should write_novels
  end
end

In this case, both assignments to @thing happen in the same context, so the last one executed wins. I, personally, would rather not have to debug that scenario.

Other thoughts?

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10718&group_id=797


More information about the rspec-devel mailing list