2015-03-21 08:15:56 -04:00
|
|
|
require "active_support/core_ext/module/attribute_accessors"
|
2015-01-23 21:26:58 -05:00
|
|
|
require "rails/test_unit/reporter"
|
2015-03-21 08:15:56 -04:00
|
|
|
require "rails/test_unit/test_requirer"
|
2015-01-23 21:26:58 -05:00
|
|
|
|
2015-03-21 08:15:56 -04:00
|
|
|
module Minitest
|
Hide Minitest's aggregated results if outputting inline.
We'd see the failures and errors reported after the run, which is needless, when we've already
reported them.
Turns:
```
.......................................S....................F
This failed
bin/rails test test/models/bunny_test.rb:14
....
Finished in 0.100886s, 1020.9583 runs/s, 1001.1338 assertions/s.
2) Failure:
BunnyTest#test_something_failing [/Users/kasperhansen/Documents/code/collection_caching_test/test/models/bunny_test.rb:15]:
This failed
103 runs, 101 assertions, 1 failures, 0 errors, 1 skips
You have skipped tests. Run with --verbose for details.
```
Into:
```
...................S.......................................F
This failed
bin/rails test test/models/bunny_test.rb:14
......................
Finished in 0.069910s, 1473.3225 runs/s, 1444.7143 assertions/s.
103 runs, 101 assertions, 1 failures, 0 errors, 1 skips
```
2015-10-07 16:23:26 -04:00
|
|
|
mattr_accessor(:hide_aggregated_results) { false }
|
|
|
|
|
|
|
|
module AggregatedResultSuppresion
|
|
|
|
def aggregated_results
|
|
|
|
super unless Minitest.hide_aggregated_results
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
SummaryReporter.prepend AggregatedResultSuppresion
|
|
|
|
|
2015-03-21 08:15:56 -04:00
|
|
|
def self.plugin_rails_options(opts, options)
|
2015-11-30 13:13:14 -05:00
|
|
|
executable = ::Rails::TestUnitReporter.executable
|
2015-03-21 08:15:56 -04:00
|
|
|
opts.separator ""
|
2015-11-16 18:49:46 -05:00
|
|
|
opts.separator "Usage: #{executable} [options] [files or directories]"
|
2015-03-21 08:15:56 -04:00
|
|
|
opts.separator "You can run a single test by appending a line number to a filename:"
|
|
|
|
opts.separator ""
|
2015-11-16 18:49:46 -05:00
|
|
|
opts.separator " #{executable} test/models/user_test.rb:27"
|
2015-03-21 08:15:56 -04:00
|
|
|
opts.separator ""
|
|
|
|
opts.separator "You can run multiple files and directories at the same time:"
|
|
|
|
opts.separator ""
|
2015-11-16 18:49:46 -05:00
|
|
|
opts.separator " #{executable} test/controllers test/integration/login_test.rb"
|
2015-03-21 08:15:56 -04:00
|
|
|
opts.separator ""
|
2015-08-30 06:33:37 -04:00
|
|
|
opts.separator "By default test failures and errors are reported inline during a run."
|
|
|
|
opts.separator ""
|
2015-03-21 08:15:56 -04:00
|
|
|
|
|
|
|
opts.separator "Rails options:"
|
2015-08-28 18:41:50 -04:00
|
|
|
opts.on("-e", "--environment ENV",
|
2015-03-21 08:15:56 -04:00
|
|
|
"Run tests in the ENV environment") do |env|
|
|
|
|
options[:environment] = env.strip
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-b", "--backtrace",
|
|
|
|
"Show the complete backtrace") do
|
|
|
|
options[:full_backtrace] = true
|
|
|
|
end
|
|
|
|
|
2015-08-30 06:33:37 -04:00
|
|
|
opts.on("-d", "--defer-output",
|
|
|
|
"Output test failures and errors after the test run") do
|
|
|
|
options[:output_inline] = false
|
|
|
|
end
|
|
|
|
|
2015-09-28 14:27:30 -04:00
|
|
|
opts.on("-f", "--fail-fast",
|
|
|
|
"Abort test run on first failure") do
|
|
|
|
options[:fail_fast] = true
|
|
|
|
end
|
|
|
|
|
2015-12-21 19:13:00 -05:00
|
|
|
opts.on("-c", "--[no-]color",
|
|
|
|
"Enable color in the output") do |value|
|
|
|
|
options[:color] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
options[:color] = true
|
Hide Minitest's aggregated results if outputting inline.
We'd see the failures and errors reported after the run, which is needless, when we've already
reported them.
Turns:
```
.......................................S....................F
This failed
bin/rails test test/models/bunny_test.rb:14
....
Finished in 0.100886s, 1020.9583 runs/s, 1001.1338 assertions/s.
2) Failure:
BunnyTest#test_something_failing [/Users/kasperhansen/Documents/code/collection_caching_test/test/models/bunny_test.rb:15]:
This failed
103 runs, 101 assertions, 1 failures, 0 errors, 1 skips
You have skipped tests. Run with --verbose for details.
```
Into:
```
...................S.......................................F
This failed
bin/rails test test/models/bunny_test.rb:14
......................
Finished in 0.069910s, 1473.3225 runs/s, 1444.7143 assertions/s.
103 runs, 101 assertions, 1 failures, 0 errors, 1 skips
```
2015-10-07 16:23:26 -04:00
|
|
|
options[:output_inline] = true
|
2015-03-21 08:15:56 -04:00
|
|
|
options[:patterns] = opts.order!
|
2015-01-23 21:26:58 -05:00
|
|
|
end
|
|
|
|
|
2015-09-06 18:53:42 -04:00
|
|
|
# Running several Rake tasks in a single command would trip up the runner,
|
|
|
|
# as the patterns would also contain the other Rake tasks.
|
|
|
|
def self.rake_run(patterns) # :nodoc:
|
|
|
|
@rake_patterns = patterns
|
2015-12-07 16:27:15 -05:00
|
|
|
passed = run
|
|
|
|
exit passed unless passed
|
|
|
|
passed
|
2015-09-06 18:53:42 -04:00
|
|
|
end
|
|
|
|
|
2015-03-21 08:15:56 -04:00
|
|
|
def self.plugin_rails_init(options)
|
|
|
|
self.run_with_rails_extension = true
|
|
|
|
|
|
|
|
ENV["RAILS_ENV"] = options[:environment] || "test"
|
|
|
|
|
2015-09-06 18:53:42 -04:00
|
|
|
unless run_with_autorun
|
2015-09-27 09:31:46 -04:00
|
|
|
patterns = defined?(@rake_patterns) ? @rake_patterns : options[:patterns]
|
|
|
|
::Rails::TestRequirer.require_files(patterns)
|
2015-09-06 18:53:42 -04:00
|
|
|
end
|
2015-03-21 08:15:56 -04:00
|
|
|
|
|
|
|
unless options[:full_backtrace] || ENV["BACKTRACE"]
|
|
|
|
# Plugin can run without Rails loaded, check before filtering.
|
2015-07-01 00:56:14 -04:00
|
|
|
Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
|
2015-03-21 08:15:56 -04:00
|
|
|
end
|
|
|
|
|
Hide Minitest's aggregated results if outputting inline.
We'd see the failures and errors reported after the run, which is needless, when we've already
reported them.
Turns:
```
.......................................S....................F
This failed
bin/rails test test/models/bunny_test.rb:14
....
Finished in 0.100886s, 1020.9583 runs/s, 1001.1338 assertions/s.
2) Failure:
BunnyTest#test_something_failing [/Users/kasperhansen/Documents/code/collection_caching_test/test/models/bunny_test.rb:15]:
This failed
103 runs, 101 assertions, 1 failures, 0 errors, 1 skips
You have skipped tests. Run with --verbose for details.
```
Into:
```
...................S.......................................F
This failed
bin/rails test test/models/bunny_test.rb:14
......................
Finished in 0.069910s, 1473.3225 runs/s, 1444.7143 assertions/s.
103 runs, 101 assertions, 1 failures, 0 errors, 1 skips
```
2015-10-07 16:23:26 -04:00
|
|
|
# Disable the extra failure output after a run, unless output is deferred.
|
|
|
|
self.hide_aggregated_results = options[:output_inline]
|
|
|
|
|
2015-12-23 17:16:54 -05:00
|
|
|
self.reporter.reporters.clear # Replace progress reporter for colors.
|
2015-12-21 19:13:00 -05:00
|
|
|
self.reporter << SummaryReporter.new(options[:io], options)
|
2015-07-01 00:56:14 -04:00
|
|
|
self.reporter << ::Rails::TestUnitReporter.new(options[:io], options)
|
2015-01-23 21:26:58 -05:00
|
|
|
end
|
2015-03-21 08:15:56 -04:00
|
|
|
|
|
|
|
mattr_accessor(:run_with_autorun) { false }
|
|
|
|
mattr_accessor(:run_with_rails_extension) { false }
|
2015-01-23 21:26:58 -05:00
|
|
|
end
|
2015-03-21 08:15:56 -04:00
|
|
|
|
2015-08-03 01:11:49 -04:00
|
|
|
Minitest.load_plugins
|
2015-01-23 21:26:58 -05:00
|
|
|
Minitest.extensions << 'rails'
|