From b25471833462b769df5d20fb4019aee46881489e Mon Sep 17 00:00:00 2001
From: Pavel Valena <pvalena@redhat.com>
Date: Fri, 16 Mar 2018 21:40:58 +0100
Subject: [PATCH] Check value of result.source_location in
 test_unit/reporter.rb#format_rerun_snippet

With Ruby 2.5 format_rerun_snippet can return nil, which crashes the test
suite, F.e.:

  TestUnitReporterTest#test_outputs_failures_inline:
  NoMethodError: undefined method `sub' for nil:NilClass
      test/test_unit/reporter_test.rb:62:in `block in <class:TestUnitReporterTest>'
  bin/rails test test/test_unit/reporter_test.rb:61
---
 railties/lib/rails/test_unit/reporter.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb
index 28b93ce..86d769d 100644
--- a/railties/lib/rails/test_unit/reporter.rb
+++ b/railties/lib/rails/test_unit/reporter.rb
@@ -68,7 +68,7 @@ def format_line(result)
       end
 
       def format_rerun_snippet(result)
-        location, line = if result.respond_to?(:source_location)
+        location, line = if result.respond_to?(:source_location) && result.source_location
           result.source_location
         else
           result.method(result.name).source_location
-- 
1.8.3.1

