123456789_123456789_123456789_123456789_123456789_

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.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(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).

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 20

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 8

attr_reader :code, :name

#name (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 8

attr_reader :code, :name

Instance Method Details

#code_and_name

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/assertion_response.rb', line 33

def code_and_name
  "#{code}: #{name}"
end