[rspec-users] mock_model outside of rails

Eric Smith esmith at 8thlight.com
Fri Apr 11 10:56:49 EDT 2008

Hello all.  I have a quick mock_model question.   Is there a way to  
use it when doing ActiveRecord testing outside of rails?  What I want  
to be able to do with my ActiveRecord is this:

class Child
	belongs_to :parent

child.parent = mock_model(Parent)

Now in rails I can do this, because mock_model does enough to fool  
ActiveRecord into think the relationship is valid, but to do this  
outside of rails I have to stub! the parent method to return the mock  
and only use the stubbed method in it.  That's not particularly safe,  
and I bet there's a simple solution to this problem.

Eric Smith

More information about the rspec-users mailing list