Skip to content

Commit 7e141a9

Browse files
committed
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 88edbef commit 7e141a9

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
@@ -58,7 +58,13 @@ def after_teardown
5858

5959
# for the SystemTesting Screenshot situation
6060
def passed?
61-
RSpec.current_example.exception.nil?
61+
return false if RSpec.current_example.exception
62+
return true unless defined?(::RSpec::Expectations::FailureAggregator)
63+
64+
failure_notifier = ::RSpec::Support.failure_notifier
65+
return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
66+
67+
failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
6268
end
6369

6470
# @private

0 commit comments

Comments
 (0)