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.



397
398
399
# File 'lib/webmock/request_pattern.rb', line 397

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

Instance Method Details

#matches?(headers) ⇒ Boolean

Returns:

  • (Boolean)


401
402
403
404
405
406
407
408
409
410
411
# File 'lib/webmock/request_pattern.rb', line 401

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



417
418
419
# File 'lib/webmock/request_pattern.rb', line 417

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

#to_sObject



413
414
415
# File 'lib/webmock/request_pattern.rb', line 413

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