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

Changeset 8559

Show
Ignore:
Timestamp:
01/05/08 02:19:48 (6 months ago)
Author:
bitsweat
Message:

assert_response failures include the exception message. Closes #10688.

Files:

Legend:

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

    r8546 r8559  
    11*SVN* 
     2 
     3* assert_response failures include the exception message.  #10688 [Seth Rasmussen] 
    24 
    35* All fragment cache keys are now by default prefixed with the "views/" namespace [DHH] 
  • trunk/actionpack/lib/action_controller/assertions/response_assertions.rb

    r8300 r8559  
    3434            assert_block("") { true } # to count the assertion 
    3535          else 
    36             assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false } 
     36            if @response.error? 
     37              assert_block(build_message(message, "Expected response to be a <?>, but was <?>\n<?>", type, @response.response_code, @response.template.instance_variable_get(:@exception).message)) { false } 
     38            else 
     39              assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false } 
     40            end 
    3741          end 
    3842        end 
  • trunk/actionpack/test/controller/action_pack_assertions_test.rb

    r7776 r8559  
    123123  # 911 
    124124  def rescue_action(e) raise; end 
     125end 
     126 
     127# Used to test that assert_response includes the exception message 
     128# in the failure message when an action raises and assert_response 
     129# is expecting something other than an error. 
     130class AssertResponseWithUnexpectedErrorController < ActionController::Base 
     131  def index 
     132    raise 'FAIL' 
     133  end 
    125134end 
    126135 
     
    466475    end 
    467476  end 
     477 
     478  def test_assert_response_uses_exception_message 
     479    @controller = AssertResponseWithUnexpectedErrorController.new 
     480    get :index 
     481    assert_response :success 
     482    flunk 'Expected non-success response' 
     483  rescue Test::Unit::AssertionFailedError => e 
     484    assert e.message.include?('FAIL') 
     485  end 
    468486end 
    469487