Skip to content

Instantly share code, notes, and snippets.

@nruth
Last active July 17, 2019 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nruth/82d10c861b612bc37c3b4d66da1d9489 to your computer and use it in GitHub Desktop.
Save nruth/82d10c861b612bc37c3b4d66da1d9489 to your computer and use it in GitHub Desktop.
Finding where deprecation warnings are coming from (Capybara, Rails, etc, anything that calls Kernel#warn)
TracePoint.trace(:c_call) do |tp|
# the various methods on tp tell you where warn is defined, but we want to know about the call stack,
# in particular the test code that the test library didn't like and decided to warn us about,
# so let's Array#grep the caller strings, filtering out the rspec library lines
if tp.method_id == :warn
app_lines = caller(0).grep(%r{enough-of-your-app-code-path-to-match/})
app_lines_without_reporter = app_lines.grep_v(/name-of-your-rspec-support-file-holding-this-code/)
p app_lines_without_reporter.join("\n")
p
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment