[rspec-devel] [ rspec-Feature Requests-6791 ] stub return values for all instances of a class

noreply at rubyforge.org noreply at rubyforge.org
Wed Jan 17 20:29:18 EST 2007


Feature Requests item #6791, was opened at 2006-11-20 16:50
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=6791&group_id=797

Category: mock module
Group: None
Status: Open
Priority: 3
Submitted By: David Chelimsky (dchelimsky)
Assigned to: Nobody (None)
Summary: stub return values for all instances of a class

Initial Comment:
I'd like to be able to do this:

SomeClass.stub_instance_method!(:method_name).and_return(specified_value)

(syntax just a suggestion)

This should set up a world in which all instances of SomeClass return specified_value for any calls to :method_name.

This differs from SomeClass.stub! in that it applies to instance methods rather than class methods.

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

Comment By: Chris Anderson (jchris)
Date: 2007-01-18 01:29

Message:
Found a solution to my specific problem:


def login_stub(user)

  controller.stub!(:current_user).and_return(user)

end


Just in case someone happens by from a google search etc.

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

Comment By: Chris Anderson (jchris)
Date: 2007-01-17 23:24

Message:
I agree. I'm trying to stub a login_as method for controller specs that won't rely on the database. I'd like to have any instance of ApplicationController stub :current_user and return my mock user. But this doesn't seem possible with the current library. Mocha has the feature, so I may lean on it for the time being.

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

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


More information about the rspec-devel mailing list