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

Store original method rather than using alias_method #75

Merged
merged 6 commits into from Apr 13, 2012

Conversation

floehopper
Copy link
Member

Using alias_method was always a bit of a kludge. Instead we can store the definition of the original method in an instance variable and then re-define it on un-stubbing if necessary.

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

I suspect there may be issues with older versions of the test-unit and minitest gems but those can wait for now.

- Instead of hiding the original method using alias_method, we can store
it as an instance variable and re-define it later if appropriate.
- Although all the tests are passing at this point, the tests in
ClassMethodTest aren't all appropriate for the new implementation. In
fact they are (like many of the unit tests) way too
implementation-specific.
- We also need to convert AnyInstanceMethod to work the same way. It
should then be possible to remove ClassMethod#hidden_method.
- This brings it into line with ClassMethod & InstanceMethod which were
changed in 1802fb936bc5a0cae46458b5f7e5b69e9dea6616. Storing the method
in an instance variable seems like a more elegant solution and has the
advantage of not changing the stubbed object's interface, albeit with an
obfuscated method name.
- As in ClassMethodTest, many tests in AnyInstanceTest are no longer
appropriate for the new implementation and like many of the unit tests
are in any case way too implementation-specific.
- It should now be possible to remove ClassMethod#hidden_method, which
was only being used by AnyInstanceMethod.
This is because we no longer use alias_method to hide the original
method; instead we store it in an instance variable and re-define it if
appropriate.
It seems like this is somehow backwardly compatible, but I haven't
investigated closely. It may cause CI failures.
floehopper added a commit that referenced this pull request Apr 13, 2012
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.
@floehopper floehopper merged commit 4d3e2bb into master Apr 13, 2012
@ghost ghost assigned floehopper Apr 21, 2012
@floehopper floehopper deleted the alias-method-alternative branch December 29, 2013 22:26
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.

6 Tests fail on Ruby 1.9.3
2 participants