Created
March 8, 2017 14:27
-
-
Save thbar/1126a933cec68d4d440cbbab6e608a45 to your computer and use it in GitHub Desktop.
A cheap class method call tracing instrumentation (without using doubles)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example of use to detect a class method call throughout a whole test suite | |
| # This could also be achieved with a RSpec double. | |
| class Dir | |
| old_method = method(:[]) | |
| define_singleton_method(:[]) do |*args| | |
| # Use failure in a test-suite where you'd need to detect use | |
| fail "FIXME - Dir[] called with args #{args.inspect}" | |
| # Or call through using this, if you only need to trace | |
| # old_method.call(*args) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment