Class: ApiValidator::Header

Inherits:
Base
  • Object
show all
Defined in:
lib/api-validator/header.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#assertions, #initialize

Constructor Details

This class inherits a constructor from ApiValidator::Base

Class Method Details

.named_expectationsObject



4
5
6
# File 'lib/api-validator/header.rb', line 4

def self.named_expectations
  @named_expectations ||= {}
end

.register(name, expected) ⇒ Object



8
9
10
# File 'lib/api-validator/header.rb', line 8

def self.register(name, expected)
  named_expectations[name] = expected
end

Instance Method Details

#validate(response) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/api-validator/header.rb', line 12

def validate(response)
  compiled_assertions = compile_assertions(response)
  response_headers = response.env[:response_headers]
  _failed_assertions = failed_assertions(compiled_assertions, response_headers)
  super.merge(
    :assertions => compiled_assertions.map(&:to_hash),
    :key => :response_headers,
    :failed_assertions => _failed_assertions.map(&:to_hash),
    :diff => diff(response_headers, _failed_assertions).map(&:to_hash),
    :valid => _failed_assertions.empty?
  )
end