diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2015-12-05 16:52:04 -0500 |
---|---|---|
committer | Arthur Nogueira Neves <github@arthurnn.com> | 2015-12-05 16:52:04 -0500 |
commit | 65443ceb0d55e1445b28e31e772629424e6755c3 (patch) | |
tree | c074e7fad8c09d424221aebb66f77df899b87f71 /actionpack/lib/action_dispatch/testing/assertions | |
parent | cb148c5ca1c80d51a8b43967692f18264c9a7029 (diff) | |
parent | 1ee87e42caa832510dfb4a1cb6c7643620447166 (diff) | |
download | rails-65443ceb0d55e1445b28e31e772629424e6755c3.tar.gz rails-65443ceb0d55e1445b28e31e772629424e6755c3.tar.bz2 rails-65443ceb0d55e1445b28e31e772629424e6755c3.zip |
Merge pull request #19977 from prathamesh-sonpatki/mention-redirect-path-in-assert-response
Add redirection path in the error message of assert_response if response is :redirect
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/assertions')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/response.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index eab20b075d..5af052afb4 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -27,6 +27,8 @@ module ActionDispatch # # Asserts that the response code was status code 401 (unauthorized) # assert_response 401 def assert_response(type, message = nil) + message ||= generate_response_message(type) + if Symbol === type if [:success, :missing, :redirect, :error].include?(type) assert_predicate @response, RESPONSE_PREDICATES[type], message @@ -82,6 +84,19 @@ module ActionDispatch handle._compute_redirect_to_location(@request, fragment) end end + + def generate_response_message(type) + message = "Expected response to be a <#{type}>, but was" + + if @response.redirection? + redirect_is = normalize_argument_to_redirection(@response.location) + message << " a redirect to <#{redirect_is}>" + else + message << " <#{@response.response_code}>" + end + + message + end end end end |