aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2013-02-06 01:03:17 -0500
committerPrem Sichanugrist <s@sikac.hu>2013-03-09 16:03:55 -0500
commit1a0c58b2988a24a783b4f9a658ac629922125551 (patch)
tree200137e5963c4bb96c22642b2d9e6135bc98cf5e /railties/lib
parent176b57c5430ddae7668114994c35b3293b0a05a5 (diff)
downloadrails-1a0c58b2988a24a783b4f9a658ac629922125551.tar.gz
rails-1a0c58b2988a24a783b4f9a658ac629922125551.tar.bz2
rails-1a0c58b2988a24a783b4f9a658ac629922125551.zip
Load fixtures only when running suites, or `-f`
* `rails test -f` will run the test suites with all fixtures loaded * New application will now generated without `fixtures :all` line enabled by default.
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/commands/test_runner.rb19
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/test_helper.rb5
2 files changed, 21 insertions, 3 deletions
diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb
index 33c32bb94f..ae901f05f8 100644
--- a/railties/lib/rails/commands/test_runner.rb
+++ b/railties/lib/rails/commands/test_runner.rb
@@ -9,7 +9,10 @@ module Rails
# of file to a new +TestRunner+ object, then invoke the evaluation. If
# the argument is not a test suite name, it will be treated as a file
# name and passed to the +TestRunner+ instance right away.
- def start(files, options)
+ def start(files, options = {})
+ original_fixtures_options = options.delete(:fixtures)
+ options[:fixtures] = true
+
case files.first
when nil
new(Dir['test/**/*_test.rb'], options).run
@@ -28,6 +31,7 @@ module Rails
when 'integration'
new(Dir['test/integration/**/*_test.rb'], options).run
else
+ options[:fixtures] = original_fixtures_options
new(files, options).run
end
end
@@ -52,6 +56,10 @@ module Rails
exit
end
+ opts.on '-f', '--fixtures', 'Load fixtures in test/fixtures/ before running the tests' do
+ options[:fixtures] = true
+ end
+
opts.on '-s', '--seed SEED', Integer, "Sets random seed" do |m|
options[:seed] = m.to_i
end
@@ -87,6 +95,15 @@ module Rails
def initialize(files, options)
@files = files
Rake::Task['test:prepare'].invoke
+
+ if options.delete(:fixtures)
+ if defined?(ActiveRecord::Base)
+ ActiveSupport::TestCase.send :include, ActiveRecord::TestFixtures
+ ActiveSupport::TestCase.fixture_path = "#{Rails.root}/test/fixtures/"
+ ActiveSupport::TestCase.fixtures :all
+ end
+ end
+
MiniTest::Unit.runner.options = options
MiniTest::Unit.output = SilentUntilSyncStream.new(MiniTest::Unit.output)
end
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 9afda2d0df..754e99e09f 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
@@ -6,11 +6,12 @@ class ActiveSupport::TestCase
<% unless options[:skip_active_record] -%>
ActiveRecord::Migration.check_pending!
- # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
+ # Uncomment the `fixtures` line below to setup all fixtures in test/fixtures/*.yml for all tests
+ # in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
- fixtures :all
+ # fixtures :all
<% end -%>
# Add more helper methods to be used by all tests here...