Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
any_instance and should_not_receive/should_receive usage (from 2.10 to 2.11) #164
After upgrading to the latest rspec-rails 2.11, I have a few failing tests involving statements like the following:
and after some investigation, I realized there is something not quite right with the tests involved even with rspec 2.10:
While I know that something has changed with should_receive and the new expectation syntax, I still cannot figure out if the tests are written wrongly, or those methods were bugged in 2.10. Also, are there plans to deprecate the should statements?
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
@alindeman I am trying to create a spec that exactly reproduces the problem (it involves a user model and customized devise registration controller used in a sign up test), but at this point I just want to know if a test with those statements should even pass with any reasonable explanation. If the passing test was bugged in 2.10, I will just fix the version in 2.11 (that is rightly failing now)
class SendEmailsToActiveUser def self.perform User.find_each do |user| user.send_email if user.active? end end end describe SendEmailsToActiveUser do it 'sends emails only to active users' do Factory.create(:user, :active => true) Factory.create(:user, :active => false) User.any_instance.should_receive(:send_email) User.any_instance.should_not_receive(:send_email) SendEmailsToActiveUser.perform end end
Here I've got
In short, I think that
There's a discussion about a new syntax (to go along with the expectation syntax) in #153. As @dchelimsky said, even if we do introduce a new syntax, it's doubtful we'd ever remove the existing syntax entirely.
I generally avoid
Still, we need to have defined behavior for