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?(obj) ⇒ 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
37 38 39 |
# File 'lib/response_code_matchers.rb', line 37 def description "be #{human_name}" end |
#failure_message ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/response_code_matchers.rb', line 41 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
49 50 51 52 53 54 55 |
# File 'lib/response_code_matchers.rb', line 49 def 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
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 |