From 9d658591d67122286f2b4aa484bd1697f183f965 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 22 Dec 2023 13:41:45 +0800 Subject: [PATCH] DEV: Fix `nil` exception when reporting rspec failures (#25011) Follow-up to f5ca96528ddc6cc14e5c86cf2172418ab863e845 Why this change? `RSpec.current_example.metadata[:extra_failure_lines]` can be `nil` and calling `<<` on `nil` is not a good idea. What does this change do? Set `RSpec.current_example.metadata[:extra_failure_lines]` to `""` as long as there are exceptions. --- spec/rails_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ba3b9c69ca0..5595e3cbdb9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -582,7 +582,7 @@ RSpec.configure do |config| config.after :each do |example| if example.exception && RspecErrorTracker.exceptions.present? - lines = RSpec.current_example.metadata[:extra_failure_lines] + lines = (RSpec.current_example.metadata[:extra_failure_lines] ||= "") lines << "~~~~~~~ SERVER EXCEPTIONS ~~~~~~~"