I have in User.rb model:
before_save { self.email.downcase! }
and I need to stub this method in users_controller_spec.rb:
User.any_instance.stubs(:before_save_callback_method).returns(true) #doesn't work
User.any_instance.stubs(:valid?).returns(true) #works
How can I do this?
You don’t really need to stub out the before_save callback, rather you can stub out methods called by the callback. You can move the behavior to a method and stub that instead.
Then in your specs: