Class: WebMock::HeadersPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/request_pattern.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ HeadersPattern

Returns a new instance of HeadersPattern.



390
391
392
# File 'lib/webmock/request_pattern.rb', line 390

def initialize(pattern)
  @pattern = WebMock::Util::Headers.normalize_headers(pattern) || {}
end

Instance Method Details

#matches?(headers) ⇒ Boolean

Returns:

  • (Boolean)


394
395
396
397
398
399
400
401
402
403
404
# File 'lib/webmock/request_pattern.rb', line 394

def matches?(headers)
  if empty_headers?(@pattern)
    empty_headers?(headers)
  else
    return false if empty_headers?(headers)
    @pattern.each do |key, value|
      return false unless headers.has_key?(key) && value === headers[key]
    end
    true
  end
end

#pp_to_sObject



410
411
412
# File 'lib/webmock/request_pattern.rb', line 410

def pp_to_s
  WebMock::Util::Headers.pp_headers_string(@pattern)
end

#to_sObject



406
407
408
# File 'lib/webmock/request_pattern.rb', line 406

def to_s
  WebMock::Util::Headers.sorted_headers_string(@pattern)
end