diff options
author | Prem Sichanugrist <s@sikac.hu> | 2013-03-09 16:03:09 -0500 |
---|---|---|
committer | Prem Sichanugrist <s@sikac.hu> | 2013-03-09 17:38:39 -0500 |
commit | 3ed41e579e45464aa6e6342783b77f9ec29e339c (patch) | |
tree | 77d2b30e6f0f7b9ec2790b30c0cb116e2dc5329c /railties/lib | |
parent | b51673fbd9563bd3ffa22e22255ca1cef80cfb6d (diff) | |
download | rails-3ed41e579e45464aa6e6342783b77f9ec29e339c.tar.gz rails-3ed41e579e45464aa6e6342783b77f9ec29e339c.tar.bz2 rails-3ed41e579e45464aa6e6342783b77f9ec29e339c.zip |
Make sure that `rails test` load test in test env
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/commands/test_runner.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/test/test_helper.rb | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 2984999a3c..41d3722c18 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -84,10 +84,9 @@ when 'test' $LOAD_PATH.unshift("./test") require 'rails/commands/test_runner' options = Rails::TestRunner.parse_arguments(ARGV) + ENV['RAILS_ENV'] ||= options[:environment] || 'test' require APP_PATH - Rails.application.require_environment! - Rails.application.load_tasks Rails::TestRunner.start(ARGV, options) when 'dbconsole' diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb index 92c4d4e593..d8857bd183 100644 --- a/railties/lib/rails/commands/test_runner.rb +++ b/railties/lib/rails/commands/test_runner.rb @@ -56,6 +56,10 @@ module Rails exit end + opts.on '-e', '--environment NAME', String, 'Specifies the environment to run this test under' do |e| + options[:environment] = e + end + opts.on '-f', '--fixtures', 'Load fixtures in test/fixtures/ before running the tests' do options[:fixtures] = true end @@ -68,8 +72,8 @@ module Rails options[:verbose] = true end - opts.on '-n', '--name PATTERN', "Filter test names on pattern (e.g. /foo/)" do |a| - options[:filter] = a + opts.on '-n', '--name PATTERN', "Filter test names on pattern (e.g. /foo/)" do |n| + options[:filter] = n end opts.separator "" @@ -94,7 +98,9 @@ module Rails # Creates a new +TestRunner+ object with a list of test file paths. def initialize(files, options) @files = files - Rake::Task['test:prepare'].invoke + + Rails.application.load_tasks + Rake::Task['db:test:load'].invoke if options.delete(:fixtures) if defined?(ActiveRecord::Base) diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index f0aeeee827..ca40914d3b 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -1,4 +1,4 @@ -ENV["RAILS_ENV"] = "test" +ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' |