Skip to content

Commit 0012b8e

Browse files
mattbrictsonJonRowe
authored andcommitted
Fix system test screenshots for aggregate failures
If RSpec's `:aggregate_failures` is enabled, a system spec with a failed expectation would not automatically trigger a screenshot as expected. This is because aggregated failures are not exposed via the typical `RSpec.current_example.exception`. To correctly detect failures when aggregation is enabled, we have to do more work. This commit works around this problem by using some behind-the-scenes knowledge of how rspec-expectations does the aggregation. Now we reach into the thread-local storage (`RSpec::Support.failure_notifier`) and discover whether there are in fact failures "queued up". If so, we will consider the example to have failed and take a screenshot. This is the same workaround as used by capybara-screenshot: mattheworiordan/capybara-screenshot#213
1 parent e941214 commit 0012b8e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ def after_teardown
2020

2121
# for the SystemTesting Screenshot situation
2222
def passed?
23-
RSpec.current_example.exception.nil?
23+
return false if RSpec.current_example.exception
24+
return true unless defined?(::RSpec::Expectations::FailureAggregator)
25+
26+
failure_notifier = ::RSpec::Support.failure_notifier
27+
return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
28+
29+
failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
2430
end
2531

2632
# @private

0 commit comments

Comments
 (0)