aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2015-01-23 21:26:58 -0500
committerYves Senn <yves.senn@gmail.com>2015-03-18 09:52:17 +0100
commita71bcdb4f3ab25594955277fa7a7c49c84cd0925 (patch)
tree5e92e993e0a332e3806f7bc88b22474f0407dc85 /railties
parent739cfd5d90aff0d8eba3d3937df63afaa6ad106f (diff)
downloadrails-a71bcdb4f3ab25594955277fa7a7c49c84cd0925.tar.gz
rails-a71bcdb4f3ab25594955277fa7a7c49c84cd0925.tar.bz2
rails-a71bcdb4f3ab25594955277fa7a7c49c84cd0925.zip
Move minitest plugin
Minitest Rails plugin should be loaded on test_help, so we report errors even when not running from the runner. Also fix the backtrace
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/test_help.rb7
-rw-r--r--railties/lib/rails/test_unit/minitest_plugin.rb15
-rw-r--r--railties/lib/rails/test_unit/runner.rb19
3 files changed, 20 insertions, 21 deletions
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 8953e5fd48..d52bb46728 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -2,6 +2,7 @@
# so fixtures aren't loaded into that environment
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
+require "rails/test_unit/minitest_plugin"
require 'active_support/testing/autorun'
require 'active_support/test_case'
require 'action_controller'
@@ -9,12 +10,6 @@ require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
require 'rails/generators/test_case'
-# Config Rails backtrace in tests.
-require 'rails/backtrace_cleaner'
-if ENV["BACKTRACE"].nil?
- Minitest.backtrace_filter = Rails.backtrace_cleaner
-end
-
if defined?(ActiveRecord::Base)
ActiveRecord::Migration.maintain_test_schema!
diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb
new file mode 100644
index 0000000000..149aad372c
--- /dev/null
+++ b/railties/lib/rails/test_unit/minitest_plugin.rb
@@ -0,0 +1,15 @@
+require "minitest"
+require "rails/test_unit/reporter"
+
+def Minitest.plugin_rails_init(options)
+ self.reporter << Rails::TestUnitReporter.new(options[:io], options)
+ if $rails_test_runner && (method = $rails_test_runner.find_method)
+ options[:filter] = method
+ end
+
+ if ENV["BACKTRACE"].nil? && !($rails_test_runner && $rails_test_runner.show_backtrace?)
+ Minitest.backtrace_filter = Rails.backtrace_cleaner
+ end
+end
+Minitest.extensions << 'rails'
+
diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb
index 31ce94a503..c777091b57 100644
--- a/railties/lib/rails/test_unit/runner.rb
+++ b/railties/lib/rails/test_unit/runner.rb
@@ -2,7 +2,6 @@ require "ostruct"
require "optparse"
require "rake/file_list"
require "method_source"
-require "rails/test_unit/reporter"
module Rails
class TestRunner
@@ -58,17 +57,7 @@ module Rails
end
def run
- enable_backtrace if @options[:backtrace]
-
$rails_test_runner = self
- def Minitest.plugin_rails_init(options)
- self.reporter << Rails::TestUnitReporter.new(options[:io], options)
- if method = $rails_test_runner.find_method
- options[:filter] = method
- end
- end
- Minitest.extensions << 'rails'
-
run_tests
end
@@ -82,6 +71,10 @@ module Rails
method[1] if method
end
+ def show_backtrace?
+ @options[:backtrace]
+ end
+
private
def run_tests
test_files.to_a.each do |file|
@@ -102,10 +95,6 @@ module Rails
Rake::FileList[pattern]
end
- def enable_backtrace
- ENV["BACKTRACE"] = "1"
- end
-
def test_methods
methods_map = []
suites = Minitest::Runnable.runnables.shuffle