This should be simple, but i can’t get it to work. I want to stub an :
@alliance.save
so that it returns true. I tried :
Alliance.stub(:save).and_return(true)
but it won’t work. Any ideas ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I’m not mistaken,
Alliance.stub(:save)would affect calls toAlliance.save. You want@alliance.stub(:save).and_return(true).Mocha has a useful method
any_instance, so you could do something likeAlliance.any_instance.stubs(:save).returns(true), which would (as the name implies) stub thesavemethod for any instance ofAlliance.