From c6fe614e45a4ae40bb635c1259423ef9e776dd40 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 6 Dec 2015 15:14:27 +0100 Subject: Show redirect response code in assert_response messages Follow-up to PR #19977, which helpfully added the redirection path to the error message of assert_response if response is a redirection, but which removed the response code, obscuring the type of redirect. This PR: - brings back the response code in the error message, - updates the tests so the new messages can be tested, - and adds test cases for the change. --- .../test/assertions/response_assertions_test.rb | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'actionpack/test/assertions') diff --git a/actionpack/test/assertions/response_assertions_test.rb b/actionpack/test/assertions/response_assertions_test.rb index 00fb1c0f12..e76c222824 100644 --- a/actionpack/test/assertions/response_assertions_test.rb +++ b/actionpack/test/assertions/response_assertions_test.rb @@ -64,14 +64,35 @@ module ActionDispatch } end - def test_message_when_response_is_redirect_but_asserted_for_status_other_than_redirect - @response = FakeResponse.new :redirection, "http://test.host/posts/redirect/1" - error = assert_raises(Minitest::Assertion) do - assert_response :success - end + def test_error_message_shows_404_when_404_asserted_for_success + @response = ActionDispatch::Response.new + @response.status = 404 + + error = assert_raises(Minitest::Assertion) { assert_response :success } + expected = "Expected response to be a , but was a <404>" + assert_match expected, error.message + end + + def test_error_message_shows_302_redirect_when_302_asserted_for_success + @response = ActionDispatch::Response.new + @response.status = 302 + @response.location = 'http://test.host/posts/redirect/1' + + error = assert_raises(Minitest::Assertion) { assert_response :success } + expected = "Expected response to be a , but was a <302>" \ + " redirect to " + assert_match expected, error.message + end + + def test_error_message_shows_302_redirect_when_302_asserted_for_301 + @response = ActionDispatch::Response.new + @response.status = 302 + @response.location = 'http://test.host/posts/redirect/2' - expected = "Expected response to be a , but was a redirect to " - assert_equal expected, error.message + error = assert_raises(Minitest::Assertion) { assert_response 301 } + expected = "Expected response to be a <301>, but was a <302>" \ + " redirect to " + assert_match expected, error.message end end end -- cgit v1.2.3