Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8022

Show
Ignore:
Timestamp:
10/26/07 02:21:21 (2 years ago)
Author:
nzkoz
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionmailer/CHANGELOG

    r7921 r8022  
    11*SVN* 
     2 
     3* Introduce a new base test class for testing Mailers.  ActionMailer::TestCase [Koz] 
    24 
    35* Fix silent failure of rxml templates.  #9879 [jstewart] 
  • trunk/actionmailer/test/abstract_unit.rb

    r7547 r8022  
    33$:.unshift "#{File.dirname(__FILE__)}/../lib" 
    44require 'action_mailer' 
     5require 'action_mailer/test_case' 
    56 
    67# Show backtraces for deprecated behavior for quicker cleanup. 
  • trunk/actionmailer/test/test_helper_test.rb

    r7070 r8022  
    99end 
    1010 
    11 class TestHelperTest < Test::Unit::TestCase 
    12   def setup 
    13     ActionMailer::Base.delivery_method = :test 
    14     ActionMailer::Base.perform_deliveries = true 
    15     ActionMailer::Base.deliveries = [] 
     11class TestHelperMailerTest < ActionMailer::TestCase 
     12 
     13  def test_setup_sets_right_action_mailer_options 
     14    assert_equal :test, ActionMailer::Base.delivery_method 
     15    assert ActionMailer::Base.perform_deliveries 
     16    assert_equal [], ActionMailer::Base.deliveries 
     17  end 
     18 
     19  def test_setup_creates_the_expected_mailer 
     20    assert @expected.is_a?(TMail::Mail) 
     21    assert_equal "1.0", @expected.mime_version 
     22    assert_equal "text/plain", @expected.content_type 
     23  end 
     24 
     25  def test_mailer_class_is_correctly_inferred 
     26    assert_equal TestHelperMailer, self.class.mailer_class 
     27  end 
     28 
     29  def test_determine_default_mailer_raises_correct_error 
     30    assert_raises(ActionMailer::NonInferrableMailerError) do 
     31      self.class.determine_default_mailer("NotAMailerTest") 
     32    end 
    1633  end 
    1734   
     35  def test_charset_is_utf_8 
     36    assert_equal "utf-8", charset 
     37  end 
     38 
     39  def test_encode 
     40    assert_equal "=?utf-8?Q?=0aasdf=0a?=", encode("\nasdf\n") 
     41  end 
     42 
    1843  def test_assert_emails 
    1944    assert_nothing_raised do 
  • trunk/actionpack/CHANGELOG

    r8019 r8022  
    11*SVN* 
     2 
     3* Introduce a new test case class for functional tests.  ActionController::TestCase. [Koz] 
    24 
    35* Fix incorrect path in helper rdoc. Closes #9926 [viktor tron] 
  • trunk/actionpack/test/controller/test_test.rb

    r7992 r8022  
    11require "#{File.dirname(__FILE__)}/../abstract_unit" 
    22require "#{File.dirname(__FILE__)}/fake_controllers" 
     3require "action_controller/test_case" 
    34 
    45class TestTest < Test::Unit::TestCase 
     
    581582  end 
    582583end 
     584 
     585class InferringClassNameTest < Test::Unit::TestCase 
     586  def test_determine_controller_class 
     587    assert_equal ContentController, determine_class("ContentControllerTest") 
     588  end 
     589 
     590  def test_determine_controller_class_with_nonsense_name 
     591    assert_raises ActionController::NonInferrableControllerError do 
     592      determine_class("HelloGoodBye") 
     593    end 
     594  end 
     595 
     596  def test_determine_controller_class_with_sensible_name_where_no_controller_exists 
     597    assert_raises ActionController::NonInferrableControllerError do 
     598      determine_class("NoControllerWithThisNameTest") 
     599    end 
     600  end 
     601 
     602  private 
     603    def determine_class(name) 
     604      ActionController::TestCase.determine_default_controller_class(name) 
     605    end 
     606end 
     607 
     608class CrazyNameTest < ActionController::TestCase 
     609  tests ContentController 
     610  def test_controller_class_can_be_set_manually_not_just_inferred 
     611    assert_equal ContentController, self.class.controller_class 
     612  end 
     613end 
     614 
  • trunk/activesupport/CHANGELOG

    r8010 r8022  
    11*SVN* 
     2 
     3* Introduce a base class for all test cases used by rails applications. ActiveSupport::TestCase [Koz] 
     4 
     5  The intention is to use this to reduce the amount of monkeypatching / overriding that  
     6  is done to test/unit's classes. 
    27 
    38* Document Enumerable and Hash #to_json.  #9970 [Chu Yeow] 
  • trunk/activesupport/lib/active_support.rb

    r7828 r8022  
    4646require 'active_support/multibyte' 
    4747 
     48require 'active_support/testing' 
     49 
  • trunk/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb

    r663 r8022  
    11require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' 
    2 require '<%= file_path %>_controller' 
    32 
    4 # Re-raise errors caught by the controller. 
    5 class <%= class_name %>Controller; def rescue_action(e) raise e end; end 
    6  
    7 class <%= class_name %>ControllerTest < Test::Unit::TestCase 
    8   def setup 
    9     @controller = <%= class_name %>Controller.new 
    10     @request    = ActionController::TestRequest.new 
    11     @response   = ActionController::TestResponse.new 
    12   end 
     3class <%= class_name %>ControllerTest < ActionController::TestCase 
     4  tests <%= class_name %>Controller 
    135 
    146  # Replace this with your real tests. 
  • trunk/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb

    r5329 r8022  
    11require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' 
    22 
    3 class <%= class_name %>Test < Test::Unit::TestCase 
    4   FIXTURES_PATH = File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../fixtures' 
    5   CHARSET = "utf-8" 
    6  
    7   include ActionMailer::Quoting 
    8  
    9   def setup 
    10     ActionMailer::Base.delivery_method = :test 
    11     ActionMailer::Base.perform_deliveries = true 
    12     ActionMailer::Base.deliveries = [] 
    13  
    14     @expected = TMail::Mail.new 
    15     @expected.set_content_type "text", "plain", { "charset" => CHARSET } 
    16     @expected.mime_version = '1.0' 
    17   end 
    18  
     3class <%= class_name %>Test < ActionMailer::TestCase 
     4  tests <%= class_name %> 
    195<% for action in actions -%> 
    206  def test_<%= action %> 
     
    2713 
    2814<% end -%> 
    29   private 
    30     def read_fixture(action) 
    31       IO.readlines("#{FIXTURES_PATH}/<%= file_path %>/#{action}") 
    32     end 
    33  
    34     def encode(subject) 
    35       quoted_printable(subject, CHARSET) 
    36     end 
     15<% if actions.blank? -%> 
     16  # replace this with your real tests 
     17  def test_truth 
     18    assert true 
     19  end 
     20<% end -%> 
    3721end 
  • trunk/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb

    r7705 r8022  
    11require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' 
    22 
    3 class <%= class_name %>Test < Test::Unit::TestCase 
     3class <%= class_name %>Test < ActiveSupport::TestCase 
    44  # Replace this with your real tests. 
    55  def test_truth 
  • trunk/railties/lib/test_help.rb

    r7395 r8022  
    66 
    77require 'test/unit' 
     8require 'active_support/test_case' 
    89require 'active_record/fixtures' 
     10require 'active_record/test_case' 
     11require 'action_controller/test_case' 
    912require 'action_controller/test_process' 
    1013require 'action_controller/integration' 
     14require 'action_mailer/test_case' 
    1115 
    1216Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/"