From 56711de495153e22ef0b91849f2e416ced5eef7d Mon Sep 17 00:00:00 2001 From: Fabio Kreusch Date: Sun, 16 May 2010 15:33:30 -0400 Subject: [PATCH] Moved rails test folders to new scheme (models, controllers, helpers and mailers), fixed generators and added update:test_directories rake task to help update to new scheme. Signed-off-by: Casey Dreier --- actionmailer/lib/rails/generators/mailer/USAGE | 2 +- .../lib/rails/generators/rails/controller/USAGE | 2 +- railties/lib/rails/generators/rails/helper/USAGE | 3 +- railties/lib/rails/generators/rails/model/USAGE | 5 +- railties/lib/rails/generators/rails/observer/USAGE | 2 +- .../generators/rails/scaffold_controller/USAGE | 2 +- .../test_unit/controller/controller_generator.rb | 2 +- .../test_unit/helper/helper_generator.rb | 2 +- .../test_unit/mailer/mailer_generator.rb | 2 +- .../test_unit/mailer/templates/functional_test.rb | 20 ------ .../test_unit/mailer/templates/mailer_test.rb | 20 ++++++ .../generators/test_unit/model/model_generator.rb | 2 +- .../test_unit/observer/observer_generator.rb | 2 +- .../test_unit/scaffold/scaffold_generator.rb | 2 +- railties/lib/rails/tasks/framework.rake | 46 +++++++++++++- railties/lib/rails/test_unit/testing.rake | 66 ++++++++++++++++---- railties/test/generators/app_generator_test.rb | 6 +- .../test/generators/controller_generator_test.rb | 8 +- railties/test/generators/helper_generator_test.rb | 2 +- railties/test/generators/mailer_generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 2 +- .../test/generators/observer_generator_test.rb | 2 +- .../test/generators/resource_generator_test.rb | 10 ++-- .../scaffold_controller_generator_test.rb | 10 ++-- .../test/generators/scaffold_generator_test.rb | 12 ++-- 25 files changed, 159 insertions(+), 75 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/test/controllers/.empty_directory delete mode 100644 railties/lib/rails/generators/rails/app/templates/test/functional/.empty_directory create mode 100644 railties/lib/rails/generators/rails/app/templates/test/helpers/.empty_directory create mode 100644 railties/lib/rails/generators/rails/app/templates/test/mailers/.empty_directory create mode 100644 railties/lib/rails/generators/rails/app/templates/test/models/.empty_directory delete mode 100644 railties/lib/rails/generators/rails/app/templates/test/unit/.empty_directory delete mode 100644 railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb create mode 100644 railties/lib/rails/generators/test_unit/mailer/templates/mailer_test.rb diff --git a/actionmailer/lib/rails/generators/mailer/USAGE b/actionmailer/lib/rails/generators/mailer/USAGE index a08d459..ec21155 100644 --- a/actionmailer/lib/rails/generators/mailer/USAGE +++ b/actionmailer/lib/rails/generators/mailer/USAGE @@ -11,5 +11,5 @@ Example: creates a Notifications mailer class, views, test, and fixtures: Mailer: app/mailers/notifications.rb Views: app/views/notifications/signup.erb [...] - Test: test/functional/notifications_test.rb + Test: test/mailers/notifications_test.rb Fixtures: test/fixtures/notifications/signup [...] diff --git a/railties/lib/rails/generators/rails/app/templates/test/controllers/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/controllers/.empty_directory new file mode 100644 index 0000000..e69de29 diff --git a/railties/lib/rails/generators/rails/app/templates/test/functional/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/functional/.empty_directory deleted file mode 100644 index e69de29..0000000 diff --git a/railties/lib/rails/generators/rails/app/templates/test/helpers/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/helpers/.empty_directory new file mode 100644 index 0000000..e69de29 diff --git a/railties/lib/rails/generators/rails/app/templates/test/mailers/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/mailers/.empty_directory new file mode 100644 index 0000000..e69de29 diff --git a/railties/lib/rails/generators/rails/app/templates/test/models/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/models/.empty_directory new file mode 100644 index 0000000..e69de29 diff --git a/railties/lib/rails/generators/rails/app/templates/test/unit/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/unit/.empty_directory deleted file mode 100644 index e69de29..0000000 diff --git a/railties/lib/rails/generators/rails/controller/USAGE b/railties/lib/rails/generators/rails/controller/USAGE index 70618a3..c22c3e8 100644 --- a/railties/lib/rails/generators/rails/controller/USAGE +++ b/railties/lib/rails/generators/rails/controller/USAGE @@ -13,6 +13,6 @@ Example: Credit card controller with URLs like /credit_card/debit. Controller: app/controllers/credit_card_controller.rb - Functional Test: test/functional/credit_card_controller_test.rb + Controllers Test: test/controllers/credit_card_controller_test.rb Views: app/views/credit_card/debit.html.erb [...] Helper: app/helpers/credit_card_helper.rb diff --git a/railties/lib/rails/generators/rails/helper/USAGE b/railties/lib/rails/generators/rails/helper/USAGE index c0ddb0f..341aea9 100644 --- a/railties/lib/rails/generators/rails/helper/USAGE +++ b/railties/lib/rails/generators/rails/helper/USAGE @@ -13,5 +13,4 @@ Example: Credit card helper. Helper: app/helpers/credit_card_helper.rb - Test: test/unit/helpers/credit_card_helper_test.rb - + Test: test/helpers/credit_card_helper_test.rb diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index db98a2d..c199e53 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -25,7 +25,7 @@ Examples: For ActiveRecord and TestUnit it creates: Model: app/models/account.rb - Test: test/unit/account_test.rb + Test: test/models/account_test.rb Fixtures: test/fixtures/accounts.yml Migration: db/migrate/XXX_add_accounts.rb @@ -39,7 +39,6 @@ Examples: Module: app/models/admin.rb Model: app/models/admin/account.rb - Test: test/unit/admin/account_test.rb + Test: test/models/admin/account_test.rb Fixtures: test/fixtures/admin_accounts.yml Migration: db/migrate/XXX_add_admin_accounts.rb - diff --git a/railties/lib/rails/generators/rails/observer/USAGE b/railties/lib/rails/generators/rails/observer/USAGE index d8f32a6..177ff49 100644 --- a/railties/lib/rails/generators/rails/observer/USAGE +++ b/railties/lib/rails/generators/rails/observer/USAGE @@ -9,4 +9,4 @@ Example: For ActiveRecord and TestUnit it creates: Observer: app/models/account_observer.rb - TestUnit: test/unit/account_observer_test.rb + TestUnit: test/models/account_observer_test.rb diff --git a/railties/lib/rails/generators/rails/scaffold_controller/USAGE b/railties/lib/rails/generators/rails/scaffold_controller/USAGE index 673f69b..419f302 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/USAGE +++ b/railties/lib/rails/generators/rails/scaffold_controller/USAGE @@ -15,6 +15,6 @@ Example: Credit card controller with URLs like /credit_card/debit. Controller: app/controllers/credit_cards_controller.rb - Functional Test: test/functional/credit_cards_controller_test.rb + Functional Test: test/controllers/credit_cards_controller_test.rb Views: app/views/credit_cards/index.html.erb [...] Helper: app/helpers/credit_cards_helper.rb diff --git a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb index 20f3bd8..db99e55 100644 --- a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb +++ b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb @@ -8,7 +8,7 @@ module TestUnit def create_test_files template 'functional_test.rb', - File.join('test/functional', class_path, "#{file_name}_controller_test.rb") + File.join('test/controllers', class_path, "#{file_name}_controller_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb index 4ea80bf..d4c2875 100644 --- a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb +++ b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb @@ -6,7 +6,7 @@ module TestUnit check_class_collision :suffix => "HelperTest" def create_helper_files - template 'helper_test.rb', File.join('test/unit/helpers', class_path, "#{file_name}_helper_test.rb") + template 'helper_test.rb', File.join('test/helpers', class_path, "#{file_name}_helper_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb index 1a49286..1bbcbef 100644 --- a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb @@ -7,7 +7,7 @@ module TestUnit check_class_collision :suffix => "Test" def create_test_files - template "functional_test.rb", File.join('test/functional', class_path, "#{file_name}_test.rb") + template "mailer_test.rb", File.join('test/mailers', class_path, "#{file_name}_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb deleted file mode 100644 index 80ac7f0..0000000 --- a/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActionMailer::TestCase -<% for action in actions -%> - test "<%= action %>" do - mail = <%= class_name %>.<%= action %> - assert_equal <%= action.to_s.humanize.inspect %>, mail.subject - assert_equal ["to@example.org"], mail.to - assert_equal ["from@example.com"], mail.from - assert_match "Hi", mail.body.encoded - end - -<% end -%> -<% if actions.blank? -%> - # replace this with your real tests - test "the truth" do - assert true - end -<% end -%> -end diff --git a/railties/lib/rails/generators/test_unit/mailer/templates/mailer_test.rb b/railties/lib/rails/generators/test_unit/mailer/templates/mailer_test.rb new file mode 100644 index 0000000..80ac7f0 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/mailer/templates/mailer_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class <%= class_name %>Test < ActionMailer::TestCase +<% for action in actions -%> + test "<%= action %>" do + mail = <%= class_name %>.<%= action %> + assert_equal <%= action.to_s.humanize.inspect %>, mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + +<% end -%> +<% if actions.blank? -%> + # replace this with your real tests + test "the truth" do + assert true + end +<% end -%> +end diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index 609b815..17c431a 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -9,7 +9,7 @@ module TestUnit check_class_collision :suffix => "Test" def create_test_file - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") + template 'unit_test.rb', File.join('test/models', class_path, "#{file_name}_test.rb") end hook_for :fixture_replacement diff --git a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb index 6cc1158..658373d 100644 --- a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb +++ b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb @@ -6,7 +6,7 @@ module TestUnit check_class_collision :suffix => "ObserverTest" def create_test_files - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb") + template 'unit_test.rb', File.join('test/models', class_path, "#{file_name}_observer_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index c0315c7..5d1ac1d 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -11,7 +11,7 @@ module TestUnit def create_test_files template 'functional_test.rb', - File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb") + File.join('test/controllers', controller_class_path, "#{controller_file_name}_controller_test.rb") end end end diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 063a393..05bc28d 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -17,7 +17,7 @@ namespace :rails do end desc "Update both configs, scripts and public/javascripts from Rails" - task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ] + task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller", "update:test_directory" ] desc "Applies the template supplied by LOCATION=/path/to/template" task :template do @@ -94,5 +94,49 @@ namespace :rails do puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary" end end + + desc "Move test directories to new locations" + task :test_directory do + if File.exists?(Rails.root.join('test')) + FileUtils.mkdir(Rails.root.join('test/mailers')) unless File.exists?(Rails.root.join('test/mailers')) + + FileUtils.mkdir(Rails.root.join('test/controllers')) unless File.exists?(Rails.root.join('test/controllers')) + [Rails.root.join('test/functional')].each do |controller_test_dir| + if File.exists?(controller_test_dir) + puts "#{controller_test_dir} exists" + FileUtils.mv(Dir["#{controller_test_dir}/**/*"], Rails.root.join('test/controllers'), :force => true) + FileUtils.rm_rf(controller_test_dir) + end + end + + if File.exists?(Rails.root.join('test/unit/helpers')) + FileUtils.mkdir(Rails.root.join('test/helpers')) unless File.exists?(Rails.root.join('test/helpers')) + FileUtils.mv(Dir[Rails.root.join('test/unit/helpers/**/*')], Rails.root.join('test/helpers'), :force => true) + FileUtils.rm_rf(Rails.root.join('test/unit/helpers')) + else + unless File.exists?(Rails.root.join('test/helpers')) + FileUtils.mkdir(Rails.root.join('test/helpers')) + end + end + + if File.exists?(Rails.root.join('test/unit')) + FileUtils.mkdir(Rails.root.join('test/models')) unless File.exists?(Rails.root.join('test/models')) + FileUtils.mv(Dir[Rails.root.join('test/unit/**/*')], Rails.root.join('test/models'), :force => true) + FileUtils.rm_rf(Rails.root.join('test/unit')) + end + end + + puts <<-TEST + + Test directories have been updated: + + test/functional -> test/controllers & test/mailers + test/unit/helpers -> test/helpers + test/unit -> test/models + + You still need to manually move your Mailers tests from test/controllers to test/mailers. + TEST + end + end end diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 79fa667..59fc764 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,4 +1,5 @@ require 'rake/testtask' +require 'active_support/deprecation' TEST_CHANGES_SINCE = Time.now - 600 @@ -40,9 +41,9 @@ module Kernel end end -desc 'Run all unit, functional and integration tests' +desc 'Run all models, controllers, helpers, mailers and integration tests' task :test do - errors = %w(test:units test:functionals test:integration).collect do |task| + errors = %w(test:models test:controllers test:helpers test:mailers test:integration).collect do |task| begin Rake::Task[task].invoke nil @@ -61,8 +62,10 @@ namespace :test do Rake::TestTask.new(:recent => "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/unit', since) + - recent_tests('app/controllers/**/*.rb', 'test/functional', since) + recent_tests('app/models/**/*.rb', 'test/models', since) + + recent_tests('app/controllers/**/*.rb', 'test/controllers', since) + + recent_tests('app/helpers/**/*.rb', 'test/helpers', since) + + recent_tests('app/mailers/**/*.rb', 'test/mailers', since) t.libs << 'test' t.test_files = touched.uniq @@ -81,28 +84,44 @@ namespace :test do models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ } controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ } + helpers = changed_since_checkin.select { |path| path =~ /app[\\\/]helpers[\\\/].*\.rb$/ } + mailers = changed_since_checkin.select { |path| path =~ /app[\\\/]mailers[\\\/].*\.rb$/ } - unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } - functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } + model_tests = models.map { |model| "test/models/#{File.basename(model, '.rb')}_test.rb" } + controller_tests = controllers.map { |controller| "test/controllers/#{File.basename(controller, '.rb')}_test.rb" } + helper_tests = helpers.map { |helper| "test/helpers/#{File.basename(helper, '.rb')}_test.rb" } + mailers_tests = mailers.map { |mailer| "test/mailers/#{File.basename(mailer, '.rb')}_test.rb" } - unit_tests.uniq + functional_tests.uniq + (model_tests + controller_tests + helper_tests + mailers_tests).uniq end t.libs << 'test' end Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" - Rake::TestTask.new(:units => "test:prepare") do |t| + Rake::TestTask.new(:models => "test:prepare") do |t| t.libs << "test" - t.pattern = 'test/unit/**/*_test.rb' + t.pattern = 'test/models/**/*_test.rb' end - Rake::Task['test:units'].comment = "Run the unit tests in test/unit" + Rake::Task['test:models'].comment = "Run tests in test/models" - Rake::TestTask.new(:functionals => "test:prepare") do |t| + Rake::TestTask.new(:controllers => "test:prepare") do |t| t.libs << "test" - t.pattern = 'test/functional/**/*_test.rb' + t.pattern = 'test/controllers/**/*_test.rb' end - Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional" + Rake::Task['test:controllers'].comment = "Run tests in test/controllers" + + Rake::TestTask.new(:helpers => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/helpers/**/*_test.rb' + end + Rake::Task['test:helpers'].comment = "Run tests in test/helpers" + + Rake::TestTask.new(:mailers => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/mailers/**/*_test.rb' + end + Rake::Task['test:mailers'].comment = "Run tests in test/mailers" Rake::TestTask.new(:integration => "test:prepare") do |t| t.libs << "test" @@ -133,4 +152,25 @@ namespace :test do end end Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)" + + # Deprecated Test Tasks + + if FileList['test/unit/**/*_test.rb'].size > 0 + Rake::TestTask.new(:units => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/unit/**/*_test.rb' + ActiveSupport::Deprecation.warn("The folder test/unit is deprecated, please update your test folder with 'rake rails:update:test_directory' and use 'rake test:models' or 'rake test:helpers' for testing.", caller) + end + Rake::Task['test:units'].comment = "DEPRECATED (Update your application with 'rake rails:update:test_directory' and use 'rake test:models' or 'rake test:helpers' for testing): Run the unit tests in test/unit" + end + + if FileList['test/functional/**/*_test.rb'].size > 0 + Rake::TestTask.new(:functionals => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/functional/**/*_test.rb' + ActiveSupport::Deprecation.warn("The folder test/functional is deprecated, please update your test folder with 'rake rails:update:test_directory' and use 'rake test:controllers' or 'rake test:mailers' for testing.", caller) + end + Rake::Task['test:functionals'].comment = "DEPRECATED (Update your application with 'rake rails:update:test_directory' and use 'rake test:controllers' or 'rake test:mailers'): Run tests in test/functional" + end + end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 3975a39..b765f7a 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -23,11 +23,13 @@ DEFAULT_APP_FILES = %w( public/javascripts public/stylesheets script/rails + test/controllers test/fixtures - test/functional + test/helpers test/integration + test/mailers + test/models test/performance - test/unit vendor vendor/plugins tmp/sessions diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index be99dc0..2974f35 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -28,23 +28,23 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_invokes_helper run_generator assert_file "app/helpers/account_helper.rb" - assert_file "test/unit/helpers/account_helper_test.rb" + assert_file "test/helpers/account_helper_test.rb" end def test_does_not_invoke_helper_if_required run_generator ["account", "--skip-helper"] assert_no_file "app/helpers/account_helper.rb" - assert_no_file "test/unit/helpers/account_helper_test.rb" + assert_no_file "test/helpers/account_helper_test.rb" end def test_invokes_default_test_framework run_generator - assert_file "test/functional/account_controller_test.rb" + assert_file "test/controllers/account_controller_test.rb" end def test_does_not_invoke_test_framework_if_required run_generator ["account", "--no-test-framework"] - assert_no_file "test/functional/account_controller_test.rb" + assert_no_file "test/controllers/account_controller_test.rb" end def test_invokes_default_template_engine diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index f0bfebd..b82a72b 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -15,7 +15,7 @@ class HelperGeneratorTest < Rails::Generators::TestCase def test_invokes_default_test_framework run_generator - assert_file "test/unit/helpers/admin_helper_test.rb", /class AdminHelperTest < ActionView::TestCase/ + assert_file "test/helpers/admin_helper_test.rb", /class AdminHelperTest < ActionView::TestCase/ end def test_logs_if_the_test_framework_cannot_be_found diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 850b45f..63cabc1 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -29,7 +29,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_invokes_default_test_framework run_generator - assert_file "test/functional/notifier_test.rb" do |test| + assert_file "test/mailers/notifier_test.rb" do |test| assert_match /class NotifierTest < ActionMailer::TestCase/, test assert_match /test "foo"/, test assert_match /test "bar"/, test diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index ef415a4..366a114 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -161,7 +161,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_invokes_default_test_framework run_generator - assert_file "test/unit/account_test.rb", /class AccountTest < ActiveSupport::TestCase/ + assert_file "test/models/account_test.rb", /class AccountTest < ActiveSupport::TestCase/ assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/ end diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb index 45fe8df..d7061b6 100644 --- a/railties/test/generators/observer_generator_test.rb +++ b/railties/test/generators/observer_generator_test.rb @@ -17,7 +17,7 @@ class ObserverGeneratorTest < Rails::Generators::TestCase def test_invokes_default_test_framework run_generator - assert_file "test/unit/account_observer_test.rb", /class AccountObserverTest < ActiveSupport::TestCase/ + assert_file "test/models/account_observer_test.rb", /class AccountObserverTest < ActiveSupport::TestCase/ end def test_logs_if_the_test_framework_cannot_be_found diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 96fd7a0..79fd081 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -18,7 +18,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase %w( app/models/account.rb - test/unit/account_test.rb + test/models/account_test.rb test/fixtures/accounts.yml ).each { |path| assert_file path } @@ -33,10 +33,10 @@ class ResourceGeneratorTest < Rails::Generators::TestCase def test_resource_controller_with_pluralized_class_name run_generator assert_file "app/controllers/accounts_controller.rb", /class AccountsController < ApplicationController/ - assert_file "test/functional/accounts_controller_test.rb", /class AccountsControllerTest < ActionController::TestCase/ + assert_file "test/controllers/accounts_controller_test.rb", /class AccountsControllerTest < ActionController::TestCase/ assert_file "app/helpers/accounts_helper.rb", /module AccountsHelper/ - assert_file "test/unit/helpers/accounts_helper_test.rb", /class AccountsHelperTest < ActionView::TestCase/ + assert_file "test/helpers/accounts_helper_test.rb", /class AccountsHelperTest < ActionView::TestCase/ end def test_resource_controller_with_actions @@ -70,14 +70,14 @@ class ResourceGeneratorTest < Rails::Generators::TestCase def test_plural_names_are_singularized content = run_generator ["accounts".freeze] assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/ - assert_file "test/unit/account_test.rb", /class AccountTest/ + assert_file "test/models/account_test.rb", /class AccountTest/ assert_match /Plural version of the model detected, using singularized version. Override with --force-plural./, content end def test_plural_names_can_be_forced content = run_generator ["accounts", "--force-plural"] assert_file "app/models/accounts.rb", /class Accounts < ActiveRecord::Base/ - assert_file "test/unit/accounts_test.rb", /class AccountsTest/ + assert_file "test/models/accounts_test.rb", /class AccountsTest/ assert_no_match /Plural version of the model detected/, content end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 8040b22..59a1214 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -54,7 +54,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase def test_helper_are_invoked_with_a_pluralized_name run_generator assert_file "app/helpers/users_helper.rb", /module UsersHelper/ - assert_file "test/unit/helpers/users_helper_test.rb", /class UsersHelperTest < ActionView::TestCase/ + assert_file "test/helpers/users_helper_test.rb", /class UsersHelperTest < ActionView::TestCase/ end def test_views_are_generated @@ -69,10 +69,10 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_no_file "app/views/layouts/users.html.erb" end - def test_functional_tests + def test_controllers_tests run_generator - assert_file "test/functional/users_controller_test.rb" do |content| + assert_file "test/controllers/users_controller_test.rb" do |content| assert_match /class UsersControllerTest < ActionController::TestCase/, content assert_match /test "should get index"/, content end @@ -85,7 +85,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_no_match /def index/, content end - assert_file "test/functional/users_controller_test.rb" do |content| + assert_file "test/controllers/users_controller_test.rb" do |content| assert_no_match /test "should get index"/, content end @@ -95,7 +95,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase def test_skip_helper_if_required run_generator ["User", "name:string", "age:integer", "--no-helper"] assert_no_file "app/helpers/users_helper.rb" - assert_no_file "test/unit/helpers/users_helper_test.rb" + assert_no_file "test/helpers/users_helper_test.rb" end def test_skip_layout_if_required diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index e8e622f..268cf04 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -12,7 +12,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Model assert_file "app/models/product_line.rb", /class ProductLine < ActiveRecord::Base/ - assert_file "test/unit/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/ + assert_file "test/models/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/ assert_file "test/fixtures/product_lines.yml" assert_migration "db/migrate/create_product_lines.rb" @@ -59,7 +59,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end - assert_file "test/functional/product_lines_controller_test.rb", + assert_file "test/controllers/product_lines_controller_test.rb", /class ProductLinesControllerTest < ActionController::TestCase/ # Views @@ -74,7 +74,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Helpers assert_file "app/helpers/product_lines_helper.rb" - assert_file "test/unit/helpers/product_lines_helper_test.rb" + assert_file "test/helpers/product_lines_helper_test.rb" # Stylesheets assert_file "public/stylesheets/scaffold.css" @@ -86,7 +86,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Model assert_no_file "app/models/product_line.rb" - assert_no_file "test/unit/product_line_test.rb" + assert_no_file "test/models/product_line_test.rb" assert_no_file "test/fixtures/product_lines.yml" assert_no_migration "db/migrate/create_product_lines.rb" @@ -97,7 +97,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Controller assert_no_file "app/controllers/product_lines_controller.rb" - assert_no_file "test/functional/product_lines_controller_test.rb" + assert_no_file "test/controllers/product_lines_controller_test.rb" # Views assert_no_file "app/views/product_lines" @@ -105,7 +105,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Helpers assert_no_file "app/helpers/product_lines_helper.rb" - assert_no_file "test/unit/helpers/product_lines_helper_test.rb" + assert_no_file "test/helpers/product_lines_helper_test.rb" # Stylesheets (should not be removed) assert_file "public/stylesheets/scaffold.css" -- 1.7.1