Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid mocks for partial mocking leaking into subsequent tests #331

Conversation

floehopper
Copy link
Member

Previously ObjectMethods#mocha & ClassMethods::AnyInstance#mocha were building mock objects for ancestor classes when ObjectReceiver#mocks or AnyInstanceReceiver#mocks was called from Mock#all_expectations as part of Mock#method_missing.

Since these mock objects were not associated with a corresponding ClassMethod or AnyInstanceMethod registered with Central via Mockery#mock_impersonating or Mockery#mock_impersonating_any_instance_of, they were not being reset as part of Central#unstub_all via Mockery#teardown and this state was leaking into subsequent tests.

You can see an example of this in #298. I've captured a more general case of this in the new acceptance test method in StubAnyInstanceMethodDefinedOnSuperclassTest which was failing before the fix in this commit.

I've also added a similar acceptance test method to StubClassMethodDefinedOnSuperclassTest which was also failing before the fix in this commit.

I'm not particularly happy with the fix, but I think it'll do for now.

Previously ObjectMethods#mocha & ClassMethods::AnyInstance#mocha were
building mock objects for ancestor classes when ObjectReceiver#mocks or
AnyInstanceReceiver#mocks was called from Mock#all_expectations as part
of Mock#method_missing.

Since these mock objects were not associated with a corresponding
ClassMethod or AnyInstanceMethod registered with Central via
Mockery#mock_impersonating or
Mockery#mock_impersonating_any_instance_of, they were not being reset as
part of Central#unstub_all via Mockery#teardown and this state was
leaking into subsequent tests.

You can see an example of this in #298. I've captured a more general
case of this in the new acceptance test method in
StubAnyInstanceMethodDefinedOnSuperclassTest which was failing before
the fix in this commit.

I've also added a similar acceptance test method to
StubClassMethodDefinedOnSuperclassTest which was also failing before
the fix in this commit.

I'm not particularly happy with the fix, but I think it'll do for now.
@floehopper floehopper merged commit 183fefc into master Apr 21, 2018
@floehopper floehopper deleted the avoid-mocks-for-partial-mocking-leaking-into-subsequent-tests branch April 21, 2018 12:30
@floehopper
Copy link
Member Author

Released in v1.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant