From d28a15ede59f6434f1b7a8d01be060fa73b4746c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Jan 2012 11:24:01 -0800 Subject: refactor assert_response --- .../lib/action_dispatch/testing/assertions/response.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/assertions') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 84c2ae716c..a9943e7afc 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -26,14 +26,17 @@ module ActionDispatch # assert_response 401 # def assert_response(type, message = nil) - if type.in?([:success, :missing, :redirect, :error]) && @response.send("#{type}?") - assert true # to count the assertion - elsif type.is_a?(Fixnum) && @response.response_code == type - assert true # to count the assertion - elsif type.is_a?(Symbol) && @response.response_code == Rack::Utils::SYMBOL_TO_STATUS_CODE[type] - assert true # to count the assertion + message ||= "Expected response to be a <#{type}>, but was <#{@response.response_code}>" + + if Symbol === type + if [:success, :missing, :redirect, :error].include?(type) + assert @response.send("#{type}?"), message + else + code = Rack::Utils::SYMBOL_TO_STATUS_CODE[type] + assert_equal @response.response_code, code, message + end else - flunk "Expected response to be a <#{type}>, but was <#{@response.response_code}>" + assert_equal type, @response.response_code, message end end -- cgit v1.2.3