From 1ee87e42caa832510dfb4a1cb6c7643620447166 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Fri, 4 Dec 2015 08:33:21 +0530 Subject: Add redirection path in the error message of assert_response if response is :redirect - If the assert_response is checking for any non-redirect response like :success and actual response is :redirect then, the error message displayed was - Expected response to be a , but was <302> - This commit adds the redirect path to the error message of assert_response if the response is :redirect. So above message is changed to - Expected response to be a , but was a redirect to --- actionpack/test/assertions/response_assertions_test.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/assertions/response_assertions_test.rb b/actionpack/test/assertions/response_assertions_test.rb index 82c747680d..6c7036aa1a 100644 --- a/actionpack/test/assertions/response_assertions_test.rb +++ b/actionpack/test/assertions/response_assertions_test.rb @@ -6,7 +6,12 @@ module ActionDispatch class ResponseAssertionsTest < ActiveSupport::TestCase include ResponseAssertions - FakeResponse = Struct.new(:response_code) do + FakeResponse = Struct.new(:response_code, :location) do + def initialize(*) + super + self.location ||= "http://test.example.com/posts" + end + [:successful, :not_found, :redirection, :server_error].each do |sym| define_method("#{sym}?") do sym == response_code @@ -58,6 +63,16 @@ module ActionDispatch assert_response :succezz } 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 + + expected = "Expected response to be a , but was a redirect to ." + assert_match expected, error.message + end end end end -- cgit v1.2.3