Class: SpecForge::Forge::Runner::HeaderValidator

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(headers, expected) ⇒ HeaderValidator

Creates a new header validator

Parameters:

  • headers (Hash)

    The response headers to validate

  • expected (Hash)

    The expected header matchers



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

Raises:



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.failure_message.lstrip)
  end

  raise Error::HeaderValidationFailure.new(@failures) if @failures.any?
end