Class: ActionDispatch::AssertionResponse
- Inherits:
-
Object
- Object
- ActionDispatch::AssertionResponse
- Defined in:
- 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 collapse
- GENERIC_RESPONSE_CODES =
:nodoc:
{ # :nodoc: success: "2XX", missing: "404", redirect: "3XX", error: "5XX" }
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #code_and_name ⇒ Object
-
#initialize(code_or_name) ⇒ AssertionResponse
constructor
Accepts a specific response status code as an Integer (404) or String (‘404’) or a response status range as a Symbol pseudo-code (:success, indicating any 200-299 status code).
Constructor Details
#initialize(code_or_name) ⇒ AssertionResponse
Accepts a specific response status code as an Integer (404) or String (‘404’) or a response status range as a Symbol pseudo-code (:success, indicating any 200-299 status code).
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/action_dispatch/testing/assertion_response.rb', line 18 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 ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/action_dispatch/testing/assertion_response.rb', line 6 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/action_dispatch/testing/assertion_response.rb', line 6 def name @name end |
Instance Method Details
#code_and_name ⇒ Object
31 32 33 |
# File 'lib/action_dispatch/testing/assertion_response.rb', line 31 def code_and_name "#{code}: #{name}" end |