Class: ActionDispatch::AssertionResponse
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actionpack/lib/action_dispatch/testing/assertion_response.rb |
Overview
This is a class that abstracts away an asserted response. It purposely does not inherit from Response
because it doesn’t need it. That means it does not have headers or a body.
Constant Summary
-
GENERIC_RESPONSE_CODES =
Internal use only
# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 12{ # :nodoc: success: "2XX", missing: "404", redirect: "3XX", error: "5XX" }
Class Method Summary
- .new(code_or_name) ⇒ AssertionResponse constructor
Instance Attribute Summary
Instance Method Summary
- #code_and_name
- #code_from_name(name) private
- #name_from_code(code) private
Constructor Details
.new(code_or_name) ⇒ AssertionResponse
# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 22
def initialize(code_or_name) if code_or_name.is_a?(Symbol) @name = code_or_name @code = code_from_name(code_or_name) else @name = name_from_code(code_or_name) @code = code_or_name end raise ArgumentError, "Invalid response name: #{name}" if @code.nil? raise ArgumentError, "Invalid response code: #{code}" if @name.nil? end
Instance Attribute Details
#code (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 10
attr_reader :code, :name
#name (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 10
attr_reader :code, :name
Instance Method Details
#code_and_name
[ GitHub ]#code_from_name(name) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 40
def code_from_name(name) GENERIC_RESPONSE_CODES[name] || Rack::Utils.status_code(name) end
#name_from_code(code) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 44
def name_from_code(code) GENERIC_RESPONSE_CODES.invert[code] || Rack::Utils::HTTP_STATUS_CODES[code] end