Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

An expectation on two classes that inherit from the same class fails. #47

Closed
xn opened this Issue Dec 20, 2011 · 9 comments

Comments

Projects
None yet
2 participants

xn commented Dec 20, 2011

mailer = mock()
mailer.stubs(:deliver!)
ServiceMailer.expects(:service_approved_notification).returns(mailer)
AdminMailer.expects(:service_approved_notification).returns(mailer)
@service.approve!
after_create do
  AdminMailer.new_service_notification(self).deliver!
  ServiceMailer.new_service_notification(self).deliver!
end
Mocha::ExpectationError: unexpected invocation: ServiceMailer.service_approved_notification(#<Service:0x8197910>)
unsatisfied expectations:
- expected exactly once, invoked twice: ServiceMailer.service_approved_notification(any_parameters)
- expected exactly once, not yet invoked: AdminMailer.service_approved_notification(any_parameters)

xn commented Dec 20, 2011

Changing the code to

mailer = mock()
mailer.stubs(:deliver!)
mailer2 = mock()
mailer2.stubs(:deliver!)
ServiceMailer.expects(:service_approved_notification).returns(mailer)
AdminMailer.expects(:service_approved_notification).returns(mailer2)
@service.approve!

Fixed the issue, but is that proper behavior?

Owner

floehopper commented Dec 21, 2011

I hope you don't mind, but I tidied up some of the formatting of you posts above.

I don't know enough about the internals of ActionMailer to answer this question immediately. I'd need to read through the ActionMailer code and I don't have time to do that at the moment.

Can you distill the unexpected behaviour into an example test without using ActionMailer?

xn commented Dec 22, 2011

Thanks and I don't mind at all. Things are crazy during the holidays, but I will try and get a clean test after the 1st. If anyone else is caught by this and needs this fixed ASAP, just comment and I'll move some of my priorities around to accommodate...

Owner

floehopper commented Dec 22, 2011

I had a quick attempt at reproducing your problem as you describe it in the issue title, but with no success i.e. it all worked as I expected. But this probably isn't actually what's happening in your scenario. That's why I'd like to try to reproduce it without the complication of ActionMailer, so we get a better idea of what's going on. Cheers, James.

xn commented Dec 25, 2011

Hurm, my specs just failed with the "fix" I posted above. I will have to get to the bottom of this soon.

xn commented Dec 25, 2011

Mocha::ExpectationError: unexpected invocation: ServiceMailer.service_approved_notification(#<Service:0x969cd10>)
unsatisfied expectations:
- expected exactly once, invoked twice: ServiceMailer.service_approved_notification(any_parameters)
- expected exactly once, not yet invoked: AdminMailer.service_approved_notification(any_parameters)
satisfied expectations:
- allowed any number of times, invoked once: #<Mock:0x97ee7b8>.deliver!(any_parameters)
- allowed any number of times, not yet invoked: #<Mock:0x97eda98>.deliver!(any_parameters)
Owner

floehopper commented Apr 13, 2012

I suspect this is related to #74.

floehopper added a commit that referenced this issue Apr 13, 2012

Merge pull request #75 from floehopper/alias-method-alternative
Store original method rather than using alias_method.

This should fix #41, #47, #74 and all tests should now pass on both Ruby 1.8.7 and 1.9.3.
Owner

floehopper commented Apr 13, 2012

I believe this issue should be resolved in the latest revision (4d3e2bb) of Mocha. @xn or @cairo140 please close the issue if you are happy with the resolution.

Owner

floehopper commented Apr 16, 2012

@xn and @cairo140 I'm marking this issue as closed. Please re-open if you disagree and explain why. Regards, James.

@floehopper floehopper closed this Apr 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment