Class: SpecForge::Forge::Runner::HeaderValidator
- Inherits:
-
Object
- Object
- SpecForge::Forge::Runner::HeaderValidator
- Defined in:
- lib/spec_forge/forge/runner/header_validator.rb
Overview
Validates HTTP response headers against expected matchers
Performs case-insensitive header name matching and runs RSpec matchers against header values.
Instance Method Summary collapse
-
#initialize(headers, expected) ⇒ HeaderValidator
constructor
Creates a new header validator.
-
#validate! ⇒ void
Validates the headers against expected matchers.
Constructor Details
#initialize(headers, expected) ⇒ HeaderValidator
Creates a new header validator
21 22 23 24 25 |
# File 'lib/spec_forge/forge/runner/header_validator.rb', line 21 def initialize(headers, expected) @headers = headers @expected = expected @failures = [] end |
Instance Method Details
#validate! ⇒ void
This method returns an undefined value.
Validates the headers against expected matchers
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spec_forge/forge/runner/header_validator.rb', line 34 def validate! @expected.each do |key, matcher| actual_key = find_header_key(key) if actual_key.nil? failure!(key, "header not found") next end actual_value = @headers[actual_key] next if matcher.matches?(actual_value) failure!(key, matcher..lstrip) end raise Error::HeaderValidationFailure.new(@failures) if @failures.any? end |