mirror of https://github.com/rails/rails
assert_response failures include the exception message. Closes #10688.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8559 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
5ccc3cf448
commit
3464a7e79c
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* assert_response failures include the exception message. #10688 [Seth Rasmussen]
|
||||
|
||||
* All fragment cache keys are now by default prefixed with the "views/" namespace [DHH]
|
||||
|
||||
* Moved the caching stores from ActionController::Caching::Fragments::* to ActiveSupport::Cache::*. If you're explicitly referring to a store, like ActionController::Caching::Fragments::MemoryStore, you need to update that reference with ActiveSupport::Cache::MemoryStore [DHH]
|
||||
|
|
|
@ -33,7 +33,11 @@ module ActionController
|
|||
elsif type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
|
||||
assert_block("") { true } # to count the assertion
|
||||
else
|
||||
assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
|
||||
if @response.error?
|
||||
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 }
|
||||
else
|
||||
assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -124,6 +124,15 @@ class ActionPackAssertionsController < ActionController::Base
|
|||
def rescue_action(e) raise; end
|
||||
end
|
||||
|
||||
# Used to test that assert_response includes the exception message
|
||||
# in the failure message when an action raises and assert_response
|
||||
# is expecting something other than an error.
|
||||
class AssertResponseWithUnexpectedErrorController < ActionController::Base
|
||||
def index
|
||||
raise 'FAIL'
|
||||
end
|
||||
end
|
||||
|
||||
module Admin
|
||||
class InnerModuleController < ActionController::Base
|
||||
def index
|
||||
|
@ -465,6 +474,15 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
|||
rescue Test::Unit::AssertionFailedError => e
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_response_uses_exception_message
|
||||
@controller = AssertResponseWithUnexpectedErrorController.new
|
||||
get :index
|
||||
assert_response :success
|
||||
flunk 'Expected non-success response'
|
||||
rescue Test::Unit::AssertionFailedError => e
|
||||
assert e.message.include?('FAIL')
|
||||
end
|
||||
end
|
||||
|
||||
class ActionPackHeaderTest < Test::Unit::TestCase
|
||||
|
|
Loading…
Reference in New Issue