[rspec-users] Not seeing the failure

Jarkko Laine jarkko at jlaine.net
Wed Jan 23 11:50:25 EST 2008


On 23.1.2008, at 18.02, Corey Haines wrote:

> I get the unexpected message :user= failure.
>
> When you set up the mock with the initial parameters, wouldn't those  
> be stubbing: @coupon.stub!(:user).and_return(@current_user)
>

You can do it like this:

@coupon = mock_model(Coupon, :user= => nil, :user =>  
@current_user, :save => true)

That stubs both user= and user. I often create reusable "mock  
factories" in spec_helper.rb that take care of the normal methods for  
AR objects:

def mock_coupon(opts = {})
   mock_model(Coupon, {:user= => nil, :user => mock_user, :save =>  
true}.merge(opts))
end

Often I also stub the errors method there because it's called pretty  
often in controllers and views.

//jarkko

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




More information about the rspec-users mailing list