On May 12, 2009, at 4:15 PM, Ben Mabey wrote:
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....
acts_as_audited has the line (acts_as_audited/lib/acts_as_audited/
audit_sweeper.rb:73)
controller.send :current_user if controller.respond_to?
(:current_user)
which blows up in my audited models. I assume there's something akin
to "controller" in controller specs and "template" in view specs that
makes it easy to do things like: controller.stub!
(:logged_in?).and_return(true) (vs. a stub on the model itself)
SR
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users