mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:51:03 +08:00
DEV: Only reveal capybara finder timeouts if the spec otherwise passes (#23026)
Followup to edb276b9a9
This commit is contained in:
parent
3a3346c95a
commit
ac85520813
|
@ -285,8 +285,11 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
module CapybaraTimeoutExtension
|
module CapybaraTimeoutExtension
|
||||||
class CapybaraTimedOut < StandardError
|
class CapybaraTimedOut < StandardError
|
||||||
def initialize(wait_time)
|
attr_reader :cause
|
||||||
super "Capybara waited for the full wait duration (#{wait_time}s). " +
|
|
||||||
|
def initialize(wait_time, cause)
|
||||||
|
@cause = cause
|
||||||
|
super "This spec passed, but capybara waited for the full wait duration (#{wait_time}s) at least once. " +
|
||||||
"This will slow down the test suite. " +
|
"This will slow down the test suite. " +
|
||||||
"Beware of negating the result of selenium's RSpec matchers."
|
"Beware of negating the result of selenium's RSpec matchers."
|
||||||
end
|
end
|
||||||
|
@ -299,8 +302,16 @@ RSpec.configure do |config|
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
seconds = session_options.default_max_wait_time if [nil, true].include? seconds
|
seconds = session_options.default_max_wait_time if [nil, true].include? seconds
|
||||||
if catch_error?(e, errors) && seconds != 0
|
if catch_error?(e, errors) && seconds != 0
|
||||||
# This error will only have been raised if the timer expired. Raise our own error instead.
|
# This error will only have been raised if the timer expired
|
||||||
raise CapybaraTimedOut.new(seconds)
|
timeout_error = CapybaraTimedOut.new(seconds, e)
|
||||||
|
if RSpec.current_example
|
||||||
|
# Store timeout for later, we'll only raise it if the test otherwise passes
|
||||||
|
RSpec.current_example.metadata[:_capybara_timeout_exception] ||= timeout_error
|
||||||
|
raise # re-raise original error
|
||||||
|
else
|
||||||
|
# Outside an example... maybe a `before(:all)` hook?
|
||||||
|
raise timeout_error
|
||||||
|
end
|
||||||
else
|
else
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
@ -310,6 +321,14 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
Capybara::Node::Base.prepend(CapybaraTimeoutExtension)
|
Capybara::Node::Base.prepend(CapybaraTimeoutExtension)
|
||||||
|
|
||||||
|
config.after(:each, type: :system) do |example|
|
||||||
|
# If test passed, but we had a capybara finder timeout, raise it now
|
||||||
|
if example.exception.nil? &&
|
||||||
|
(capybara_timout_error = example.metadata[:_capybara_timeout_exception])
|
||||||
|
raise capybara_timout_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# possible values: OFF, SEVERE, WARNING, INFO, DEBUG, ALL
|
# possible values: OFF, SEVERE, WARNING, INFO, DEBUG, ALL
|
||||||
browser_log_level = ENV["SELENIUM_BROWSER_LOG_LEVEL"] || "SEVERE"
|
browser_log_level = ENV["SELENIUM_BROWSER_LOG_LEVEL"] || "SEVERE"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user