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


_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to