aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/test_runner_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-04-05 14:49:06 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-04-05 14:49:06 -0700
commit91efe3958a7618db4030dd6ee5d8693145fb7b94 (patch)
treed0a54aae66db97b515738a1ab67e01b367dead18 /railties/test/application/test_runner_test.rb
parent2ac97df55230cdadce008a6b8993de52056779bb (diff)
parent01034d3be0d7c8c09b551ac612c4b18f86086dc5 (diff)
downloadrails-91efe3958a7618db4030dd6ee5d8693145fb7b94.tar.gz
rails-91efe3958a7618db4030dd6ee5d8693145fb7b94.tar.bz2
rails-91efe3958a7618db4030dd6ee5d8693145fb7b94.zip
Merge branch 'railstest'
* railstest: do not blow away the test database on every run just check pending migrations in the current environment check pending migrations against the test db only match the default task test no longer makes sense after requiring all test files switch the testing tests to use rake a test file can be provided to rake, e.g.: switch to Rails::TestTask default task should also be in the test env ensure the schema checking is done in the dev connection Revert "Update Rake tasks to call `rails test` instead" Revert "Warning removed unused variable task_name" apps that depend on active record should load fixtures
Diffstat (limited to 'railties/test/application/test_runner_test.rb')
-rw-r--r--railties/test/application/test_runner_test.rb60
1 files changed, 23 insertions, 37 deletions
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 56ca3bc1a9..405f6af295 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -15,14 +15,6 @@ module ApplicationTests
teardown_app
end
- def test_should_not_display_heading
- create_test_file
- run_test_command.tap do |output|
- assert_no_match "Run options:", output
- assert_no_match "Running tests:", output
- end
- end
-
def test_run_in_test_environment
app_file 'test/unit/env_test.rb', <<-RUBY
require 'test_helper'
@@ -45,6 +37,7 @@ module ApplicationTests
def test_run_single_file
create_test_file :models, 'foo'
+ create_test_file :models, 'bar'
assert_match "1 tests, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb")
end
@@ -62,24 +55,14 @@ module ApplicationTests
error_stream = Tempfile.new('error')
redirect_stderr(error_stream) { run_test_command('test/models/error_test.rb') }
- assert_match "SyntaxError", error_stream.read
- end
-
- def test_invoke_rake_db_test_load
- app_file "lib/tasks/test.rake", <<-RUBY
- task 'db:test:load' do
- puts "Hello World"
- end
- RUBY
- create_test_file
- assert_match "Hello World", run_test_command
+ assert_match "syntax error", error_stream.read
end
def test_run_models
create_test_file :models, 'foo'
create_test_file :models, 'bar'
create_test_file :controllers, 'foobar_controller'
- run_test_command("models").tap do |output|
+ run_test_models_command.tap do |output|
assert_match "FooTest", output
assert_match "BarTest", output
assert_match "2 tests, 2 assertions, 0 failures", output
@@ -90,7 +73,7 @@ module ApplicationTests
create_test_file :helpers, 'foo_helper'
create_test_file :helpers, 'bar_helper'
create_test_file :controllers, 'foobar_controller'
- run_test_command('helpers').tap do |output|
+ run_test_helpers_command.tap do |output|
assert_match "FooHelperTest", output
assert_match "BarHelperTest", output
assert_match "2 tests, 2 assertions, 0 failures", output
@@ -102,7 +85,7 @@ module ApplicationTests
create_test_file :helpers, 'bar_helper'
create_test_file :unit, 'baz_unit'
create_test_file :controllers, 'foobar_controller'
- run_test_command('units').tap do |output|
+ run_test_units_command.tap do |output|
assert_match "FooTest", output
assert_match "BarHelperTest", output
assert_match "BazUnitTest", output
@@ -114,7 +97,7 @@ module ApplicationTests
create_test_file :controllers, 'foo_controller'
create_test_file :controllers, 'bar_controller'
create_test_file :models, 'foo'
- run_test_command('controllers').tap do |output|
+ run_test_controllers_command.tap do |output|
assert_match "FooControllerTest", output
assert_match "BarControllerTest", output
assert_match "2 tests, 2 assertions, 0 failures", output
@@ -125,7 +108,7 @@ module ApplicationTests
create_test_file :mailers, 'foo_mailer'
create_test_file :mailers, 'bar_mailer'
create_test_file :models, 'foo'
- run_test_command('mailers').tap do |output|
+ run_test_mailers_command.tap do |output|
assert_match "FooMailerTest", output
assert_match "BarMailerTest", output
assert_match "2 tests, 2 assertions, 0 failures", output
@@ -137,7 +120,7 @@ module ApplicationTests
create_test_file :controllers, 'bar_controller'
create_test_file :functional, 'baz_functional'
create_test_file :models, 'foo'
- run_test_command('functionals').tap do |output|
+ run_test_functionals_command.tap do |output|
assert_match "FooMailerTest", output
assert_match "BarControllerTest", output
assert_match "BazFunctionalTest", output
@@ -148,7 +131,7 @@ module ApplicationTests
def test_run_integration
create_test_file :integration, 'foo_integration'
create_test_file :models, 'foo'
- run_test_command('integration').tap do |output|
+ run_test_integration_command.tap do |output|
assert_match "FooIntegration", output
assert_match "1 tests, 1 assertions, 0 failures", output
end
@@ -178,19 +161,12 @@ module ApplicationTests
end
RUBY
- run_test_command('test/unit/chu_2_koi_test.rb -n test_rikka').tap do |output|
+ run_test_command('test/unit/chu_2_koi_test.rb TESTOPTS="-n test_rikka"').tap do |output|
assert_match "Rikka", output
assert_no_match "Sanae", output
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
suites = [:models, :helpers, [:units, :unit], :controllers, :mailers,
@@ -199,7 +175,7 @@ module ApplicationTests
suites.each do |suite, directory|
directory ||= suite
create_fixture_test directory
- assert_match "3 users", run_test_command(suite)
+ assert_match "3 users", run_task(["test:#{suite}"])
Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" }
end
end
@@ -220,6 +196,7 @@ module ApplicationTests
end
def test_run_different_environment_using_e_tag
+ env = "development"
app_file 'test/unit/env_test.rb', <<-RUBY
require 'test_helper'
@@ -230,7 +207,7 @@ module ApplicationTests
end
RUBY
- assert_match "development", run_test_command('-e development test/unit/env_test.rb')
+ assert_match env, run_test_command("test/unit/env_test.rb RAILS_ENV=#{env}")
end
def test_generated_scaffold_works_with_rails_test
@@ -239,8 +216,17 @@ module ApplicationTests
end
private
+ def run_task(tasks)
+ Dir.chdir(app_path) { `bundle exec rake #{tasks.join ' '}` }
+ end
+
def run_test_command(arguments = 'test/unit/test_test.rb')
- Dir.chdir(app_path) { `bundle exec rails test #{arguments}` }
+ run_task ['test', arguments]
+ end
+ %w{ mailers models helpers units controllers functionals integration }.each do |type|
+ define_method("run_test_#{type}_command") do
+ run_task ["test:#{type}"]
+ end
end
def create_model_with_fixture