Class: RSpec::Http::HeaderMatcher
- Inherits:
-
Object
- Object
- RSpec::Http::HeaderMatcher
- Defined in:
- lib/rspec/http/header_matchers.rb
Constant Summary collapse
- NO_VALUE =
Object.new
Instance Attribute Summary collapse
-
#expected_value ⇒ Object
readonly
Returns the value of attribute expected_value.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected) ⇒ HeaderMatcher
constructor
A new instance of HeaderMatcher.
- #matches?(response) ⇒ Boolean
Constructor Details
#initialize(expected) ⇒ HeaderMatcher
Returns a new instance of HeaderMatcher.
7 8 9 |
# File 'lib/rspec/http/header_matchers.rb', line 7 def initialize(expected) @header, @expected_value = expected.kind_of?(String) ? [expected, NO_VALUE] : expected.first end |
Instance Attribute Details
#expected_value ⇒ Object (readonly)
Returns the value of attribute expected_value.
4 5 6 |
# File 'lib/rspec/http/header_matchers.rb', line 4 def expected_value @expected_value end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/rspec/http/header_matchers.rb', line 4 def header @header end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/rspec/http/header_matchers.rb', line 4 def response @response end |
Instance Method Details
#description ⇒ Object
25 26 27 |
# File 'lib/rspec/http/header_matchers.rb', line 25 def description @matcher.description end |
#failure_message ⇒ Object
29 30 31 |
# File 'lib/rspec/http/header_matchers.rb', line 29 def @matcher. end |
#failure_message_when_negated ⇒ Object
33 34 35 |
# File 'lib/rspec/http/header_matchers.rb', line 33 def @matcher. end |
#matches?(response) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rspec/http/header_matchers.rb', line 11 def matches?(response) if response[header] @matcher = case expected_value when String then HeaderStringMatcher.new(header, expected_value) when Regexp then HeaderRegexpMatcher.new(header, expected_value) when NO_VALUE then HeaderPresenceMatcher.new(header) else raise SyntaxError.new("The value for a header should be either a String or a Regexp and not of type #{expected_value.class}") end else @matcher = HeaderPresenceMatcher.new(header) end @matcher.matches?(response) end |