1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Only fake uplevel when not supported natively by the Ruby version

This commit is contained in:
Thomas Walpole 2020-09-06 12:31:16 -07:00
parent 676a21e13a
commit d6a4c8c116

View file

@ -81,8 +81,11 @@ module Capybara
new_trace.first.split(/:in /, 2).first
end
# Workaround for emulating `warn '...', uplevel: n` in Ruby 2.5 or lower.
def warn(message, uplevel: 1)
return Kernel.warn(message, uplevel: uplevel) if RUBY_VERSION >= '2.6'
# TODO: Remove when we drop support for Ruby 2.5
# Workaround for emulating `warn '...', uplevel: n` in Ruby 2.5 or lower.
if (match = /^(?<file>.+?):(?<line>\d+)(?::in `.*')?/.match(caller[uplevel]))
location = [match[:file], match[:line]].join(':')
Kernel.warn "#{location}: #{message}"