Skip to content

Instantly share code, notes, and snippets.

@thbar
Created March 8, 2017 14:27
Show Gist options
  • Select an option

  • Save thbar/1126a933cec68d4d440cbbab6e608a45 to your computer and use it in GitHub Desktop.

Select an option

Save thbar/1126a933cec68d4d440cbbab6e608a45 to your computer and use it in GitHub Desktop.
A cheap class method call tracing instrumentation (without using doubles)
# 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