Module: Cucumber::Rest::Status

Defined in:
lib/cucumber/rest/status.rb

Overview

Helper functions for checking the cacheability of responses.

Class Method Summary collapse

Class Method Details

.ensure_status(expected, response: HttpCapture::RESPONSES.last) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/cucumber/rest/status.rb', line 9

def self.ensure_status(expected, response: HttpCapture::RESPONSES.last)
  actual = response.status
  unless expected == actual
    actual_name = Rack::Utils::HTTP_STATUS_CODES[actual]
    expected_name = Rack::Utils::HTTP_STATUS_CODES[expected]
    message = "Request status was #{actual} #{actual_name}; expected #{expected} #{expected_name}"
    raise message
  end
end

.ensure_status_class(expected, response: HttpCapture::RESPONSES.last) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cucumber/rest/status.rb', line 19

def self.ensure_status_class(expected, response: HttpCapture::RESPONSES.last)
  min = case expected
        when :informational then 100
        when :success then 200
        when :redirection then 300
        when :client_error then 400
        when :server_error then 500
        end
  max = min + 99
  expected_range = min..max
  actual = response.status
  unless expected_range === actual
    message = "Request status was #{actual} #{Rack::Utils::HTTP_STATUS_CODES[actual]}; expected #{expected_range}"
    raise message
  end
end