[rspec-users] Newbie question

Tom Stuart tom at experthuman.com
Tue Dec 4 10:58:03 EST 2007


On 4 Dec 2007, at 15:41, Andy Goundry wrote:
> I've created the following spec test to simply ensure that the  
> Account model receives a call to :new, but the spec is failing as it  
> also receives a call to :save! and it isn't expecting it. I am using  
> "@account = mock_model(Account)". If i replace this with "@account =  
> mock('account', :null_object => true)" the test passes, but i'm not  
> sure that's really what i want. I'm pretty sure i need to us  
> mock_model in this instance.

mock_model doesn't do anything magic -- it just creates a mock (with a  
conveniently-chosen name) and stubs out a few useful methods for you.  
In your case you need to stub out #save! too, so that you don't get  
the failure: @account = mock_model(Account, :save! => true).

Cheers,
-Tom


More information about the rspec-users mailing list