Class: ResponseCodeMatchers::ResponseCodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/response_code_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected, name) ⇒ ResponseCodeMatcher

Returns a new instance of ResponseCodeMatcher.



18
19
20
21
# File 'lib/response_code_matchers.rb', line 18

def initialize(expected, name)
  @expected = expected
  @name     = name
end

Instance Method Details

#descriptionObject



37
38
39
# File 'lib/response_code_matchers.rb', line 37

def description
  "be #{human_name}"
end

#failure_messageObject



41
42
43
44
45
46
47
# File 'lib/response_code_matchers.rb', line 41

def failure_message
  if @valid
    "expected response code to be #@expected, but #@actual"
  else
    "expected #{method_name} to return true, got false"
  end
end

#failure_message_when_negatedObject



49
50
51
52
53
54
55
# File 'lib/response_code_matchers.rb', line 49

def failure_message_when_negated
  if @valid
    "expected response code not to be #@expected, but #@actual"
  else
    "expected #{method_name} to return false, got true"
  end
end

#matches?(obj) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/response_code_matchers.rb', line 23

def matches?(obj)
  return obj.__send__(method_name) unless obj.respond_to?(:header) && obj.respond_to?(:body)

  if @valid = obj.respond_to?(:code)
    @actual = obj.code
    @actual == @expected
  elsif @valid = obj.respond_to?(:status)
    @actual = obj.status.to_s
    @actual == @expected
  else
    obj.__send__(method_name)
  end
end