aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
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/test
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/test')
-rw-r--r--railties/test/application/test_runner_test.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 249bfd1d5d..71e2b403af 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -1,4 +1,5 @@
require 'isolation/abstract_unit'
+require 'active_support/core_ext/string/strip'
module ApplicationTests
class TestRunnerTest < ActiveSupport::TestCase
@@ -170,11 +171,61 @@ module ApplicationTests
end
end
+ def test_not_load_fixtures_when_running_single_test
+ create_model_with_fixture
+ create_fixture_test :models, 'user'
+ assert_match /0 users/, run_test_command('test/models/user_test.rb')
+ assert_match /3 users/, run_test_command('test/models/user_test.rb -f')
+ end
+
+ def test_load_fixtures_when_running_test_suites
+ create_model_with_fixture
+ types = [:models, :helpers, [:units, :unit], :controllers, :mailers,
+ [:functionals, :functional], :integration]
+
+ types.each do |type, directory|
+ directory ||= type
+ create_fixture_test directory
+ assert_match /3 users/, run_test_command(type)
+ Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" }
+ end
+ end
+
private
def run_test_command(arguments = 'test/unit/test_test.rb')
Dir.chdir(app_path) { `bundle exec rails test #{arguments}` }
end
+ def create_model_with_fixture
+ script 'generate model user name:string'
+
+ app_file 'test/fixtures/users.yml', <<-YAML.strip_heredoc
+ vampire:
+ id: 1
+ name: Koyomi Araragi
+ crab:
+ id: 2
+ name: Senjougahara Hitagi
+ cat:
+ id: 3
+ name: Tsubasa Hanekawa
+ YAML
+
+ Dir.chdir(app_path) { `bundle exec rake db:migrate` }
+ end
+
+ def create_fixture_test(path = :unit, name = 'test')
+ app_file "test/#{path}/#{name}_test.rb", <<-RUBY
+ require 'test_helper'
+
+ class #{name.camelize}Test < ActiveSupport::TestCase
+ def test_fixture
+ puts "\#{User.count} users (\#{__FILE__})"
+ end
+ end
+ RUBY
+ end
+
def create_schema
app_file 'db/schema.rb', ''
end