class Faraday::Adapter::Test::Stub

Public Class Methods

new(full, headers, body, block) click to toggle source
Calls superclass method
# File lib/faraday/adapter/test.rb, line 127
def initialize(full, headers, body, block)
  path, query = full.respond_to?(:split) ? full.split("?") : full
  params = query ?
    Faraday::Utils.parse_nested_query(query) :
    {}
  super(path, params, headers, body, block)
end

Public Instance Methods

headers_match?(request_headers) click to toggle source
# File lib/faraday/adapter/test.rb, line 163
def headers_match?(request_headers)
  headers.keys.all? do |key|
    request_headers[key] == headers[key]
  end
end
matches?(request_uri, request_headers, request_body) click to toggle source
# File lib/faraday/adapter/test.rb, line 135
def matches?(request_uri, request_headers, request_body)
  request_path, request_query = request_uri.split('?')
  request_params = request_query ?
    Faraday::Utils.parse_nested_query(request_query) :
    {}
  # meta is a hash use as carrier
  # that will be yielded to consumer block
  meta = {}
  return path_match?(request_path, meta) &&
    params_match?(request_params) &&
    (body.to_s.size.zero? || request_body == body) &&
    headers_match?(request_headers), meta
end
params_match?(request_params) click to toggle source
# File lib/faraday/adapter/test.rb, line 157
def params_match?(request_params)
  params.keys.all? do |key|
    request_params[key] == params[key]
  end
end
path_match?(request_path, meta) click to toggle source
# File lib/faraday/adapter/test.rb, line 149
def path_match?(request_path, meta)
  if path.is_a? Regexp
    !!(meta[:match_data] = path.match(request_path))
  else
    path == request_path
  end
end
to_s() click to toggle source
# File lib/faraday/adapter/test.rb, line 169
def to_s
  "#{path} #{body}"
end