Class: DebugExceptionsJson::Rspec::Matchers::StatusCodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/debug_exceptions_json/rspec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_code) ⇒ StatusCodeMatcher

Returns a new instance of StatusCodeMatcher.



12
13
14
# File 'lib/debug_exceptions_json/rspec/matchers.rb', line 12

def initialize(expected_code)
  @expected = expected_code
end

Instance Method Details

#descriptionObject



38
39
40
# File 'lib/debug_exceptions_json/rspec/matchers.rb', line 38

def description
  "respond with numeric status code #{@expected}"
end

#failure_messageObject Also known as: failure_message_for_should



16
17
18
19
20
21
22
23
24
# File 'lib/debug_exceptions_json/rspec/matchers.rb', line 16

def failure_message
  message = "expected the response to have status code #{@expected} but it was #{@actual}."

  if dump_exception?(@response)
    [message, dumped_exception].join("\n\n")
  else
    message
  end
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



27
28
29
30
31
32
33
34
35
# File 'lib/debug_exceptions_json/rspec/matchers.rb', line 27

def failure_message_when_negated
  message = "expected the response not to have status code #{@expected} but it did"

  if dump_exception?(@response)
    [message, dumped_exception].join("\n\n")
  else
    message
  end
end

#matches?(response) ⇒ Boolean

response - A Rack::Response

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/debug_exceptions_json/rspec/matchers.rb', line 43

def matches?(response)
  @response = response
  @actual = response.status
  @actual == @expected
end