[rspec-devel] [ rspec-Bugs-15638 ] When naming a protected method, if it begins with 'should_' it causes it to be treated as an example.

noreply at rubyforge.org noreply at rubyforge.org
Thu Nov 15 15:02:12 EST 2007


Bugs item #15638, was opened at 2007-11-15 01:32
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=15638&group_id=797

Category: runner module
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Nathan Sutton (fowlduck)
Assigned to: Nobody (None)
Summary: When naming a protected method, if it begins with 'should_' it causes it to be treated as an example.

Initial Comment:
starting a protected method with should_ causes it to be treated as an example.

edge rails revision: 8146
edge rspec revision: 2889
edge rspec_on_rails revision: 2889

describe SessionsController do

  # a bunch of examples, some that call should_be_logged_in

protected

  def should_be_logged_in
    response.session.should_not be_nil
    session[:user].should_not be_nil
  end

end

When running the spec:

SessionsController should_be_logged_in' FAILED
expected not nil, got nil
./spec/controllers/sessions_controller_spec.rb:111:in `should_be_logged_in'
script/spec:4:


Renamed the method to 'be_logged_in' and all specs then pass.  Line 111, in this case, is 'session[:user].should_not be_nil'.



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

>Comment By: Nathan Sutton (fowlduck)
Date: 2007-11-15 14:02

Message:
Well, I'm using methods starting with should to group examples for a specific 
purpose.  If there was a way to do this and re-use them then I wouldn't be doing 
this in the first place.  I would use shared behaviors but you can't pass values 
into them.  Maybe the solution is not to remove this, but to define a way to 
accomplish what I was trying to do, one that won't get stomped on.


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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-11-15 13:57

Message:
It's not only a matter of a pit-stop. It's that some people would prefer to stay in class/method land and use this format from day one and keep it that way:

class FooSpec < Spec::ExampleGroup
  def should_bar
    ...
  end
end

My opinion is that this is a reasonable request and that there's no reason not to offer it - except for this conflict with helpers that start w/ should.

You can't start helpers with test in test unit, I don't see why this should be a big deal.

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-11-15 13:50

Message:
I think we should kill the feature. test_ methods and it blocks is enough. I don't think we need another pit stop in between.

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

Comment By: Nathan Sutton (fowlduck)
Date: 2007-11-15 10:51

Message:
This is the cause of bug #15637 and the subtlety of it will cause breakage for 
those who don't expect it.  How long did we spend trying to figure this out?

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

Comment By: Nathan Sutton (fowlduck)
Date: 2007-11-15 10:39

Message:
Maybe not kill it, but make it a configuration option?  Also, I think this is the 
reason that my specs were failing last night concerning the inclusion of the 
module, bug #15637.

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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-11-15 08:58

Message:
I'd sooner kill the feature. That sort of subtlety would make things very confusing.

In my view, the feature is either in or out.

Thoughts?

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

Comment By: Nathan Sutton (fowlduck)
Date: 2007-11-15 01:46

Message:
Would it be possible to only do this for public methods, and exclude protected 
ones?

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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-11-15 01:44

Message:
That's actually by design. In an effort to play well with others, we're working towards a world in which people who prefer to use classes and methods can do this:

class FooSpec < Spec::ExampleGroup
  def should_bar
    ...
  end
end

This works just like Test::Unit except it looks for methods that start with "should" instead of "test". This means that you can not have helper methods that start with "should".

I'm going to leave this ticket open and would welcome opinions on this.

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

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


More information about the rspec-devel mailing list