diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/test.rb | 16 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/reporter.rb | 22 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/runner.rb | 27 |
3 files changed, 62 insertions, 3 deletions
diff --git a/railties/lib/rails/commands/test.rb b/railties/lib/rails/commands/test.rb index f75b07cf73..5c997336a0 100644 --- a/railties/lib/rails/commands/test.rb +++ b/railties/lib/rails/commands/test.rb @@ -1,9 +1,19 @@ ENV["RAILS_ENV"] = "test" - require "rails/test_unit/runner" -options = Rails::TestRunner::Options.parse(ARGV) +require "rails/test_unit/reporter" +options = Rails::TestRunner::Options.parse(ARGV) $: << File.expand_path("../../test", APP_PATH) +$runner = Rails::TestRunner.new(options) + +def Minitest.plugin_rails_init(options) + self.reporter << Rails::TestUnitReporter.new(options[:io], options) + if method = $runner.find_method + options[:filter] = "/^(#{method})$/" + end +end +Minitest.extensions << 'rails' + # Config Rails backtrace in tests. -Rails::TestRunner.new(options).run +$runner.run diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb new file mode 100644 index 0000000000..bd4d455589 --- /dev/null +++ b/railties/lib/rails/test_unit/reporter.rb @@ -0,0 +1,22 @@ +require "minitest" + +module Rails + class TestUnitReporter < Minitest::StatisticsReporter + def report + io.puts + io.puts "Failed test:" + io.puts + io.puts aggregated_results + end + + def aggregated_results # :nodoc: + filtered_results = results.dup + filtered_results.reject!(&:skipped?) unless options[:verbose] + filtered_results.map do |result| + result.failures.map { |failure| + "bin/rails test #{failure.location}\n" + }.join "\n" + end.join + end + end +end diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index 25f30f6b80..6f9fdab68a 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -1,6 +1,7 @@ require "ostruct" require "optparse" require "rake/file_list" +require "method_source" module Rails class TestRunner @@ -53,6 +54,14 @@ module Rails run_tests end + def find_method + return if @line.blank? + method = test_methods.find do |test_method, start_line, end_line| + (start_line..end_line).include?(@line.to_i) + end + method.first if method + end + private def run_tests test_files.to_a.each do |file| @@ -66,6 +75,10 @@ module Rails def test_files if @options[:pattern] pattern = NAMED_PATTERNS[@options[:pattern]] + unless pattern + filename, @line = @options[:pattern].split(':') + return [filename] if filename + end else pattern = "test/**/*_test.rb" end @@ -79,5 +92,19 @@ module Rails def filter_tests_by_name ARGV.push("-n", @options[:name]) end + + def test_methods + methods_map = [] + suites = Minitest::Runnable.runnables.shuffle + suites.each do |suite_class| + suite_class.runnable_methods.each do |test_method| + method = suite_class.instance_method(test_method) + start_line = method.source_location.last + end_line = method.source.split("\n").size + start_line - 1 + methods_map << [test_method, start_line, end_line] + end + end + methods_map + end end end |