diff options
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/all.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/test/test_helper.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/sub_test_task.rb | 24 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/testing.rake | 71 |
4 files changed, 67 insertions, 35 deletions
diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 19c2226619..1493815c30 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -1,6 +1,6 @@ require "rails" -if defined?(Rake) && Rake.application.top_level_tasks.grep(/^test(?::|$)/).any? +if defined?(Rake) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any? ENV['RAILS_ENV'] ||= 'test' 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 ca40914d3b..4fd060341e 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,12 +6,11 @@ class ActiveSupport::TestCase <% unless options[:skip_active_record] -%> ActiveRecord::Migration.check_pending! - # Uncomment the `fixtures :all` line below to setup all fixtures in test/fixtures/*.yml - # for all tests in alphabetical order. + # 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... 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 |