diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-08-30 12:33:37 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-28 20:30:03 +0200 |
commit | 64a3b09b408400c94fd25f22c2ce791a8d90b5cb (patch) | |
tree | 1013b9eca4e937b964209ee8648b37f42d7fc812 /railties/lib/rails/test_unit | |
parent | 9254d7eb11304fc43609e3f96acfcd730f18b738 (diff) | |
download | rails-64a3b09b408400c94fd25f22c2ce791a8d90b5cb.tar.gz rails-64a3b09b408400c94fd25f22c2ce791a8d90b5cb.tar.bz2 rails-64a3b09b408400c94fd25f22c2ce791a8d90b5cb.zip |
Add inline failure reporting to test runner.
Any failures or errors will be reported inline during the run by default.
Skipped tests will be reported if run in verbose mode.
Any result is output with failure messages and a rerun snippet for that test.
Rerun snippets won't be output after a run, unless `--defer-output` is passed.
Diffstat (limited to 'railties/lib/rails/test_unit')
-rw-r--r-- | railties/lib/rails/test_unit/minitest_plugin.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/reporter.rb | 30 |
2 files changed, 32 insertions, 5 deletions
diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index 1923433c4a..b65d67b2a5 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -14,6 +14,8 @@ module Minitest opts.separator "" opts.separator " bin/rails test test/controllers test/integration/login_test.rb" opts.separator "" + opts.separator "By default test failures and errors are reported inline during a run." + opts.separator "" opts.separator "Rails options:" opts.on("-e", "--environment ENV", @@ -26,6 +28,11 @@ module Minitest options[:full_backtrace] = true end + opts.on("-d", "--defer-output", + "Output test failures and errors after the test run") do + options[:output_inline] = false + end + options[:patterns] = opts.order! end diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb index 09b8675cf8..c88e9aa60e 100644 --- a/railties/lib/rails/test_unit/reporter.rb +++ b/railties/lib/rails/test_unit/reporter.rb @@ -6,8 +6,21 @@ module Rails class_attribute :executable self.executable = "bin/rails test" + def record(result) + super + + if output_inline? && result.failure && (!result.skipped? || options[:verbose]) + io.puts + io.puts + io.puts result.failures.map(&:message) + io.puts + io.puts format_rerun_snippet(result) + io.puts + end + end + def report - return if filtered_results.empty? + return if output_inline? || filtered_results.empty? io.puts io.puts "Failed tests:" io.puts @@ -15,10 +28,7 @@ module Rails end def aggregated_results # :nodoc: - filtered_results.map do |result| - location, line = result.method(result.name).source_location - "#{self.executable} #{relative_path_for(location)}:#{line}" - end.join "\n" + filtered_results.map { |result| format_rerun_snippet(result) }.join "\n" end def filtered_results @@ -32,5 +42,15 @@ module Rails def relative_path_for(file) file.sub(/^#{Rails.root}\/?/, '') end + + private + def output_inline? + options.fetch(:output_inline, true) + end + + def format_rerun_snippet(result) + location, line = result.method(result.name).source_location + "#{self.executable} #{relative_path_for(location)}:#{line}" + end end end |