Ticket #10688: assert_response_with_exception_message_for_500.diff
| File assert_response_with_exception_message_for_500.diff, 3.3 kB (added by loincloth, 9 months ago) |
|---|
-
actionpack/test/controller/action_pack_assertions_test.rb
old new 27 27 28 28 # a redirect to an external location 29 29 def redirect_external() redirect_to "http://www.rubyonrails.org"; end 30 31 # a 404 32 def response404() head '404 AWOL' end 33 34 # a 500 35 def response500() head '500 Sorry' end 36 30 31 ActionController::StatusCodes::STATUS_CODES.each do |code,message| 32 define_method("response#{code}") { head "#{code} #{message}" } 33 end 34 37 35 # a fictional 599 38 36 def response599() head '599 Whoah!' end 39 37 40 38 # putting stuff in the flash 41 39 def flash_me 42 40 flash['hello'] = 'my name is inigo montoya...' … … 124 122 def rescue_action(e) raise; end 125 123 end 126 124 125 # Used to test that assert_response includes the exception message 126 # in the failure message when an action raises and assert_response 127 # is expecting something other than an error. 128 class AssertResponseWithUnexpectedErrorController < ActionController::Base 129 def index 130 raise 'FAIL' 131 end 132 end 133 127 134 module Admin 128 135 class InnerModuleController < ActionController::Base 129 136 def index … … 465 472 rescue Test::Unit::AssertionFailedError => e 466 473 end 467 474 end 475 476 ActionController::StatusCodes::STATUS_CODES.keys.each do |code| 477 define_method "test assert_response #{code}" do 478 get "response#{code}" 479 assert_response code 480 end 481 end 482 483 def test_assert_response_uses_exception_message 484 @controller = AssertResponseWithUnexpectedErrorController.new 485 get :index 486 begin 487 assert_response :success 488 rescue Test::Unit::AssertionFailedError => e 489 assert e.message.include?('FAIL') 490 end 491 end 468 492 end 469 493 470 494 class ActionPackHeaderTest < Test::Unit::TestCase -
actionpack/lib/action_controller/assertions/response_assertions.rb
old new 33 33 elsif type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type] 34 34 assert_block("") { true } # to count the assertion 35 35 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 37 41 end 38 42 end 39 43 end 40 44 41 45 # Assert that the redirection options passed in match those of the redirect called in the latest action. 42 46 # This match can be partial, such that assert_redirected_to(:controller => "weblog") will also 43 47 # match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on.