Class: ResponseCodeMatchers::ResponseCodeMatcher
- Inherits:
-
Object
- Object
- ResponseCodeMatchers::ResponseCodeMatcher
- Defined in:
- lib/response_code_matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected, name) ⇒ ResponseCodeMatcher
constructor
A new instance of ResponseCodeMatcher.
- #matches?(response) ⇒ Boolean
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
#description ⇒ Object
35 36 37 |
# File 'lib/response_code_matchers.rb', line 35 def description "be #{human_name}" end |
#failure_message ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/response_code_matchers.rb', line 39 def if @valid "expected response code to be #@expected, but #@actual" else "expected #{method_name} to return true, got false" end end |
#failure_message_when_negated ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/response_code_matchers.rb', line 47 def if @valid "expected response code not to be #@expected, but #@actual" else "expected #{method_name} to return false, got true" end end |
#matches?(response) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/response_code_matchers.rb', line 23 def matches?(response) if @valid = response.respond_to?(:code) @actual = response.code @actual == @expected elsif @valid = response.respond_to?(:status) @actual = response.status.to_s @actual == @expected else response.__send__(method_name) end end |