diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-04-05 14:49:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-04-05 14:49:06 -0700 |
commit | 91efe3958a7618db4030dd6ee5d8693145fb7b94 (patch) | |
tree | d0a54aae66db97b515738a1ab67e01b367dead18 /railties/lib/rails/test_unit | |
parent | 2ac97df55230cdadce008a6b8993de52056779bb (diff) | |
parent | 01034d3be0d7c8c09b551ac612c4b18f86086dc5 (diff) | |
download | rails-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/lib/rails/test_unit')
-rw-r--r-- | railties/lib/rails/test_unit/sub_test_task.rb | 24 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/testing.rake | 71 |
2 files changed, 64 insertions, 31 deletions
diff --git a/railties/lib/rails/test_unit/sub_test_task.rb b/railties/lib/rails/test_unit/sub_test_task.rb index 87b6f9b5a4..36657dbdd4 100644 --- a/railties/lib/rails/test_unit/sub_test_task.rb +++ b/railties/lib/rails/test_unit/sub_test_task.rb @@ -1,6 +1,28 @@ +require 'rake/testtask' + module Rails + class TestTask < Rake::TestTask # :nodoc: all + def initialize(name = :test) + super + @libs << "test" # lib *and* test seem like a better default + end + + def define + task @name do + if ENV['TESTOPTS'] + ARGV.replace Shellwords.split ENV['TESTOPTS'] + end + libs = @libs - $LOAD_PATH + $LOAD_PATH.unshift(*libs) + file_list.each { |fl| + FileList[fl].to_a.each { |f| require File.expand_path f } + } + end + end + end + # Silence the default description to cut down on `rake -T` noise. - class SubTestTask < Rake::TestTask + class SubTestTask < Rake::TestTask # :nodoc: def desc(string) # Ignore the description. end diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 3c247f32c0..07d2c192e4 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,7 +1,6 @@ require 'rbconfig' require 'rake/testtask' require 'rails/test_unit/sub_test_task' -require 'active_support/deprecation' TEST_CHANGES_SINCE = Time.now - 600 @@ -48,10 +47,15 @@ task default: :test desc 'Runs test:units, test:functionals, test:integration together' task :test do - if ENV['TEST'] - exec "bundle exec rails test #{ENV['TEST'].inspect}" + tasks = Rake.application.top_level_tasks + test_files = tasks.grep(/^test\//) + if test_files.any? + Rails::TestTask.new('test:single') { |t| + t.test_files = test_files + } + Rake::Task['test:single'].invoke else - exec 'bundle exec rails test' + Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke end end @@ -60,15 +64,11 @@ namespace :test do # Placeholder task for other Railtie and plugins to enhance. See Active Record for an example. end - task :run do - ActiveSupport::Deprecation.warn "`rake test:run` is deprecated. Please use `rails test`." - exec 'bundle exec rails test' - end + task :run => ['test:units', 'test:functionals', 'test:integration'] # Inspired by: http://ngauthier.com/2012/02/quick-tests-with-bash.html desc "Run tests quickly by merging all types and not resetting db" - Rake::TestTask.new(:all) do |t| - t.libs << "test" + Rails::TestTask.new(:all) do |t| t.pattern = "test/**/*_test.rb" end @@ -77,12 +77,9 @@ namespace :test do task :db => %w[db:test:prepare test:all] end - # Display deprecation message - task :deprecated do - ActiveSupport::Deprecation.warn "`rake #{ARGV.first}` is deprecated with no replacement." - end + Rails::TestTask.new(recent: "test:prepare") do |t| + warn "DEPRECATION WARNING: `rake test:recent` is deprecated" - Rake::TestTask.new(recent: ["test:deprecated", "test:prepare"]) do |t| since = TEST_CHANGES_SINCE touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + recent_tests('app/models/**/*.rb', 'test/models', since) + @@ -90,12 +87,13 @@ namespace :test do recent_tests('app/controllers/**/*.rb', 'test/controllers', since) + recent_tests('app/controllers/**/*.rb', 'test/functional', since) - t.libs << 'test' t.test_files = touched.uniq end - Rake::Task['test:recent'].comment = "Deprecated; Test recent changes" + Rake::Task['test:recent'].comment = "Test recent changes" + + Rails::TestTask.new(uncommitted: "test:prepare") do |t| + warn "DEPRECATION WARNING: `rake test:uncommitted` is deprecated" - Rake::TestTask.new(uncommitted: ["test:deprecated", "test:prepare"]) do |t| def t.file_list if File.directory?(".svn") changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] } @@ -114,23 +112,36 @@ namespace :test do controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } (unit_tests + functional_tests).uniq.select { |file| File.exist?(file) } end + end + Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" - t.libs << 'test' + Rails::TestTask.new(single: "test:prepare") + + Rails::TestTask.new(models: "test:prepare") do |t| + t.pattern = 'test/models/**/*_test.rb' end - Rake::Task['test:uncommitted'].comment = "Deprecated; Test changes since last checkin (only Subversion and Git)" - desc "Deprecated; Please use `rails test \"#{ENV['TEST']}\"`" - task :single do - ActiveSupport::Deprecation.warn "`rake test:single` is deprecated. Please use `rails test \"#{ENV['TEST']}\"`." - exec "bundle exec rails test #{test_suit_name}" + Rails::TestTask.new(helpers: "test:prepare") do |t| + t.pattern = 'test/helpers/**/*_test.rb' end - [:models, :helpers, :units, :controllers, :functionals, :integration].each do |test_suit_name| - desc "Deprecated; Please use `rails test #{test_suit_name}`" - task test_suit_name do - ActiveSupport::Deprecation.warn "`rake test:#{test_suit_name}` is deprecated. Please use `rails test #{test_suit_name}`." + Rails::TestTask.new(units: "test:prepare") do |t| + t.pattern = 'test/{models,helpers,unit}/**/*_test.rb' + end - exec "bundle exec rails test #{test_suit_name}" - end + Rails::TestTask.new(controllers: "test:prepare") do |t| + t.pattern = 'test/controllers/**/*_test.rb' + end + + Rails::TestTask.new(mailers: "test:prepare") do |t| + t.pattern = 'test/mailers/**/*_test.rb' + end + + Rails::TestTask.new(functionals: "test:prepare") do |t| + t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb' + end + + Rails::TestTask.new(integration: "test:prepare") do |t| + t.pattern = 'test/integration/**/*_test.rb' end end |