Parent

Class/Module Index [+]

Quicksearch

WebMock::BodyPattern

Constants

BODY_FORMATS

Public Class Methods

new(pattern) click to toggle source
# File lib/webmock/request_pattern.rb, line 138
def initialize(pattern)
  @pattern = pattern
  if (@pattern).is_a?(Hash)
    @pattern = normalize_hash(@pattern)
  end
end

Public Instance Methods

matches?(body, content_type = "") click to toggle source
# File lib/webmock/request_pattern.rb, line 145
def matches?(body, content_type = "")
  if (@pattern).is_a?(Hash)
    return true if @pattern.empty?

    case BODY_FORMATS[content_type]
    when :json then
      matching_hashes?(WebMock::Util::JSON.parse(body), @pattern)
    when :xml then
      matching_hashes?(Crack::XML.parse(body), @pattern)
    else
      matching_hashes?(Addressable::URI.parse('?' + body).query_values, @pattern)
    end
  else
    empty_string?(@pattern) && empty_string?(body) ||
      @pattern == body ||
      @pattern === body
  end
end
to_s() click to toggle source
# File lib/webmock/request_pattern.rb, line 164
def to_s
  @pattern.inspect
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.