Class: RSpec::Http::HeaderPresenceMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/http/header_matchers.rb

Direct Known Subclasses

HeaderRegexpMatcher, HeaderStringMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ HeaderPresenceMatcher

Returns a new instance of HeaderPresenceMatcher.



40
41
42
# File 'lib/rspec/http/header_matchers.rb', line 40

def initialize(header)
  @header = header
end

Instance Attribute Details

#expected_valueObject (readonly)

Returns the value of attribute expected_value.



39
40
41
# File 'lib/rspec/http/header_matchers.rb', line 39

def expected_value
  @expected_value
end

#headerObject (readonly)

Returns the value of attribute header.



39
40
41
# File 'lib/rspec/http/header_matchers.rb', line 39

def header
  @header
end

#responseObject (readonly)

Returns the value of attribute response.



39
40
41
# File 'lib/rspec/http/header_matchers.rb', line 39

def response
  @response
end

Instance Method Details

#descriptionObject



53
54
55
# File 'lib/rspec/http/header_matchers.rb', line 53

def description
  "Verify the presence of '#{header}' among the response headers"
end

#failure_messageObject



57
58
59
# File 'lib/rspec/http/header_matchers.rb', line 57

def failure_message
  "The header '#{header}' was not found"
end

#failure_message_when_negatedObject



61
62
63
# File 'lib/rspec/http/header_matchers.rb', line 61

def failure_message_when_negated
  "The header '#{header}' should not have been found, but it was and it has a value of '#{response[header]}'"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/rspec/http/header_matchers.rb', line 44

def matches?(response)
  @response = response
  validate
end

#validateObject



49
50
51
# File 'lib/rspec/http/header_matchers.rb', line 49

def validate
  response[header]
end