[rspec-users] stub with assigns?

Jarkko Laine jarkko at jlaine.net
Thu Dec 13 02:06:08 EST 2007


On 13.12.2007, at 9.00, Jonathan Linowes wrote:

> is there a way to stub a method that sets an instance variable, so  
> the stub sets it too?
>
> def find_foo
>   @foo = Foo.find(params[:id]
> end
>
>
> ...
> controller.stub!(:find_foo).and_assigns(:foo, "123")

Why don't you just stub Foo.find? That way the instance var gets  
assigned automatically.

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




More information about the rspec-users mailing list