aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-10-21 11:27:26 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2016-10-21 13:10:26 -0700
commit797f1dd63c68eb44c1af358d377cfef271e685c5 (patch)
tree32aa16b9fc05ee202afca56f002c884b770737fd /railties
parent54a5b99a007dd773aa25183fa29e7c87a86a29da (diff)
downloadrails-797f1dd63c68eb44c1af358d377cfef271e685c5.tar.gz
rails-797f1dd63c68eb44c1af358d377cfef271e685c5.tar.bz2
rails-797f1dd63c68eb44c1af358d377cfef271e685c5.zip
Prevent the test framework from being loaded in production mode
The test framework should not be autoloaded in production mode. Before this commit, the testing railtie would extend AS::TestCase. This caused AS::TestCase to be preloaded regardless of the environment in which we were running. This commit just moves the code that adds line filtering support in to the test command where we actually execute the test runner. That allows us to maintain the line runner feature but only load the minimal amount of code we need.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands/test/test_command.rb5
-rw-r--r--railties/lib/rails/test_unit/railtie.rb6
-rw-r--r--railties/test/application/runner_test.rb9
3 files changed, 14 insertions, 6 deletions
diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb
index 1b2e3af9cc..e97b9cbbba 100644
--- a/railties/lib/rails/commands/test/test_command.rb
+++ b/railties/lib/rails/commands/test/test_command.rb
@@ -1,5 +1,6 @@
require "rails/command"
require "rails/test_unit/minitest_plugin"
+require "rails/test_unit/line_filtering"
module Rails
module Command
@@ -11,6 +12,10 @@ module Rails
def perform(*)
$LOAD_PATH << Rails::Command.root.join("test")
+ # Add test line filtering support for running test by line number
+ # via the command line.
+ ActiveSupport::TestCase.extend Rails::LineFiltering
+
Minitest.run_via[:rails] = true
require "active_support/testing/autorun"
diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb
index d0fc795515..ec91673e40 100644
--- a/railties/lib/rails/test_unit/railtie.rb
+++ b/railties/lib/rails/test_unit/railtie.rb
@@ -1,5 +1,3 @@
-require "rails/test_unit/line_filtering"
-
if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any?
ENV["RAILS_ENV"] ||= "test"
end
@@ -13,10 +11,6 @@ module Rails
c.integration_tool :test_unit
end
- initializer "test_unit.line_filtering" do
- ActiveSupport::TestCase.extend Rails::LineFiltering
- end
-
rake_tasks do
load "rails/test_unit/testing.rake"
end
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
index 77e7a2cca5..8769703f66 100644
--- a/railties/test/application/runner_test.rb
+++ b/railties/test/application/runner_test.rb
@@ -43,6 +43,15 @@ module ApplicationTests
assert_match "42", Dir.chdir(app_path) { `bin/rails runner "bin/count_users.rb"` }
end
+ def test_no_minitest_loaded_in_production_mode
+ app_file "bin/print_features.rb", <<-SCRIPT
+ p $LOADED_FEATURES.grep(/minitest/)
+ SCRIPT
+ assert_match "[]", Dir.chdir(app_path) {
+ `RAILS_ENV=production bin/rails runner "bin/print_features.rb"`
+ }
+ end
+
def test_should_set_dollar_0_to_file
app_file "bin/dollar0.rb", <<-SCRIPT
puts $0