class ActionDispatch::AssertionResponse
does not have headers or a body.
does not inherit from Response because it doesn’t need it. That means it
This is a class that abstracts away an asserted response. It purposely
def code_and_name
def code_and_name "#{code}: #{name}" end
def code_from_name(name)
def code_from_name(name) GENERIC_RESPONSE_CODES[name] || Rack::Utils.status_code(name) end
def initialize(code_or_name)
('404') or a response status range as a Symbol pseudo-code (:success,
Accepts a specific response status code as an Integer (404) or String
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
def name_from_code(code)
def name_from_code(code) GENERIC_RESPONSE_CODES.invert[code] || Rack::Utils::HTTP_STATUS_CODES[code] end