Show backtrace for some depreaction calls

This commit is contained in:
Thomas Walpole 2020-07-05 13:18:37 -07:00
parent 38b7878112
commit 922d661476
6 changed files with 16 additions and 5 deletions

View File

@ -86,7 +86,7 @@ module Capybara
def deprecate(method, alternate_method, once = false)
@deprecation_notified ||= {}
unless once && @deprecation_notified[method]
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead: #{Capybara::Helpers.filter_backtrace(caller)}"
end
@deprecation_notified[method] = true
end

View File

@ -70,6 +70,17 @@ module Capybara
count == 1 ? singular : plural
end
def filter_backtrace(trace)
return 'No backtrace' unless trace
filter = %r{lib/capybara/|lib/rspec/|lib/minitest/}
new_trace = trace.take_while { |line| line !~ filter }
new_trace = trace.reject { |line| line =~ filter } if new_trace.empty?
new_trace = trace.dup if new_trace.empty?
new_trace.first.split(/:in /, 2).first
end
if defined?(Process::CLOCK_MONOTONIC)
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
else

View File

@ -68,7 +68,7 @@ module Capybara
# @deprecated Use {#matches_style?} instead.
#
def has_style?(styles, **options)
warn 'DEPRECATED: has_style? is deprecated, please use matches_style?'
warn "DEPRECATED: has_style? is deprecated, please use matches_style? : #{Capybara::Helpers.filter_backtrace(caller)}"
matches_style?(styles, **options)
end

View File

@ -14,7 +14,7 @@ module Capybara
if expected_text.nil? && !exact?
warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. '\
'Please specify a string or regexp instead.'
"Please specify a string or regexp instead. #{Capybara::Helpers.filter_backtrace(caller)}"
end
@expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s

View File

@ -154,7 +154,7 @@ module Capybara
# @deprecated
#
def have_style(styles, **options)
warn 'DEPRECATED: have_style is deprecated, please use match_style'
warn "DEPRECATED: have_style is deprecated, please use match_style : #{Capybara::Helpers.filter_backtrace(caller)}"
match_style(styles, **options)
end

View File

@ -3,7 +3,7 @@
Capybara.add_selector(:css, locator_type: [String, Symbol], raw_locator: true) do
css do |css|
if css.is_a? Symbol
warn "DEPRECATED: Passing a symbol (#{css.inspect}) as the CSS locator is deprecated - please pass a string instead."
warn "DEPRECATED: Passing a symbol (#{css.inspect}) as the CSS locator is deprecated - please pass a string instead : #{Capybara::Helpers.filter_backtrace(caller)}"
end
css
end