[rspec-users] Top level object in model specs

Ben Mabey ben at benmabey.com
Tue May 12 17:15:32 EDT 2009


Steven Rogers wrote:
>
> I want to stub a global method in a model spec, but I can't figure out 
> what's the equivalent in model specs for controller.stub! in 
> controller specs and template.stub! in view specs . . . at least, it 
> seems like I need to do that in order to make acts_as_audited happy in 
> models. Any thoughts?
>
> Thanks,
> Steve

I"m not sure what you mean by global method.  Do you mean class method? 
If so then ModelName.stub!(:class_method) should work.  If you are 
talking about an instance method then you just need to call stub! on the 
instance (it can be a mock object or a real object.)

What is the exact problem you are running into though?  Mocking may not 
be the best option....

-Ben


More information about the rspec-users mailing list