diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-10-26 02:21:21 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-10-26 02:21:21 +0000 |
commit | 2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab (patch) | |
tree | 3ad613f6c73cd9fef243f7586dfcf3b6f329105b /railties/lib | |
parent | 2bfd6772a4f3f9e0ff395cfd415dafbc1c9dec80 (diff) | |
download | rails-2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab.tar.gz rails-2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab.tar.bz2 rails-2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab.zip |
Introduce TestCase subclasses for testing rails applications allowing tests to be DRY'd up a bit and to provide a path toward tidying up our monkeypatching of test/unit.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8022 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib')
4 files changed, 15 insertions, 35 deletions
diff --git a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb index abe9c4cf8c..202a017a40 100644 --- a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb @@ -1,15 +1,7 @@ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' -require '<%= file_path %>_controller' -# Re-raise errors caught by the controller. -class <%= class_name %>Controller; def rescue_action(e) raise e end; end - -class <%= class_name %>ControllerTest < Test::Unit::TestCase - def setup - @controller = <%= class_name %>Controller.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end +class <%= class_name %>ControllerTest < ActionController::TestCase + tests <%= class_name %>Controller # Replace this with your real tests. def test_truth diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb index 8cb816efc0..dcd0206211 100644 --- a/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb @@ -1,21 +1,7 @@ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' -class <%= class_name %>Test < Test::Unit::TestCase - FIXTURES_PATH = File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../fixtures' - CHARSET = "utf-8" - - include ActionMailer::Quoting - - def setup - ActionMailer::Base.delivery_method = :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries = [] - - @expected = TMail::Mail.new - @expected.set_content_type "text", "plain", { "charset" => CHARSET } - @expected.mime_version = '1.0' - end - +class <%= class_name %>Test < ActionMailer::TestCase + tests <%= class_name %> <% for action in actions -%> def test_<%= action %> @expected.subject = '<%= class_name %>#<%= action %>' @@ -26,12 +12,10 @@ class <%= class_name %>Test < Test::Unit::TestCase end <% end -%> - private - def read_fixture(action) - IO.readlines("#{FIXTURES_PATH}/<%= file_path %>/#{action}") - end - - def encode(subject) - quoted_printable(subject, CHARSET) - end +<% if actions.blank? -%> + # replace this with your real tests + def test_truth + assert true + end +<% end -%> end diff --git a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb index ec8010c8ae..9bb3ca4160 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' -class <%= class_name %>Test < Test::Unit::TestCase +class <%= class_name %>Test < ActiveSupport::TestCase # Replace this with your real tests. def test_truth assert true diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index a7401e6e93..13bac2d8d4 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -5,9 +5,13 @@ require_dependency 'application' silence_warnings { RAILS_ENV = "test" } require 'test/unit' +require 'active_support/test_case' require 'active_record/fixtures' +require 'active_record/test_case' +require 'action_controller/test_case' require 'action_controller/test_process' require 'action_controller/integration' +require 'action_mailer/test_case' Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/" ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path |