diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-11-12 21:39:58 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-11-12 21:39:58 +0100 |
commit | 0db310586ac3e15be95d2ef27ff40cfa24c05c10 (patch) | |
tree | abef833a897ede9e2ac6cfb82d0147b98d091436 /railties/lib/rails | |
parent | 49eefe123a1a032fb44bc5fef049d29c759fb157 (diff) | |
download | rails-0db310586ac3e15be95d2ef27ff40cfa24c05c10.tar.gz rails-0db310586ac3e15be95d2ef27ff40cfa24c05c10.tar.bz2 rails-0db310586ac3e15be95d2ef27ff40cfa24c05c10.zip |
Prefer Minitest's location for test failures.
When running tests, the Rails test runner would report the start of the test method as the test failure.
For this test:
```ruby
1 require 'test_helper
2
3 class BunnyTest < ActiveSupport::TestCase
4 test "something failing" do
5 assert false, 'This failed'
6 end
7 end
```
The runner outputs 5 instead of 4:
```
............................................F
This failed
bin/rails test test/models/bunny_test.rb:5
........
```
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/test_unit/reporter.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb index e1fe92a11b..de4b002e55 100644 --- a/railties/lib/rails/test_unit/reporter.rb +++ b/railties/lib/rails/test_unit/reporter.rb @@ -57,8 +57,14 @@ module Rails end def format_rerun_snippet(result) - location, line = result.method(result.name).source_location - "#{self.executable} #{relative_path_for(location)}:#{line}" + # Try to extract path to assertion from backtrace. + if result.location =~ /\[(.*)\]\z/ + assertion_path = $1 + else + assertion_path = result.method(result.name).source_location.join(':') + end + + "#{self.executable} #{relative_path_for(assertion_path)}" end end end |