Class: RiotRails::ActionController::ResponseCodeMacro

Inherits:
Riot::AssertionMacro
  • Object
show all
Defined in:
lib/riot/action_controller/assertion_macros.rb

Overview

Asserts that the HTTP response code equals your expectation. You can use the symbolized form of the status code or the integer code itself. Not currently supporting status ranges; such as: :success, :redirect, etc.

controller.response_code(:ok)
controller.response_code(200)

controller.response_code(:not_found)
controller.response_code(404)

# A redirect
controller.response_code(:found)
controller.response_code(302)

See ActionController::StatusCodes for the list of available codes.

Instance Method Summary collapse

Instance Method Details

#evaluate(actual, expected_code) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/riot/action_controller/assertion_macros.rb', line 64

def evaluate(actual, expected_code)
  if expected_code.kind_of?(Symbol)
    expected_code = ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[expected_code]
  end
  actual_code = actual.response.response_code
  if expected_code == actual_code
    pass("returns response code #{expected_code}")
  else
    fail("expected response code #{expected_code}, not #{actual_code}")
  end
end