Suppose this ruby code is:
class User
def self.failed_login!(email)
user = User.find_by_email(email)
if user
user.failed_login_count = user.failed_login_count + 1
user.save
end
end
end
I want to write a test that checks that user.save is never called when an invalid email address is specified. For example:.
it "should not increment failed login count" do
User.expects(:save).never()
User.failed_login!("doesnotexist")
end
This test is currently passing, but it is also passing when I provide a valid email address.
How to set up wait with Mocha? (or any other mocking framework), so that it checks the method of saving any instance of the user that is never called?
(preferably without bypassing / bullying the find_by_email method, since the implementation of how to force the user to change in the future)
Greetings
source
share