Permalink
Browse files

refactor assert_response

  • Loading branch information...
1 parent 01d1794 commit d28a15ede59f6434f1b7a8d01be060fa73b4746c @tenderlove tenderlove committed Jan 6, 2012
Showing with 10 additions and 7 deletions.
  1. +10 −7 actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -26,14 +26,17 @@ module ResponseAssertions
# 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

0 comments on commit d28a15e

Please sign in to comment.