class Faraday::Adapter::Test::Stub
Public Class Methods
new(host, full, headers, body, block)
click to toggle source
Calls superclass method
# File lib/faraday/adapter/test.rb, line 133 def initialize(host, full, headers, body, block) path, query = full.respond_to?(:split) ? full.split("?") : full params = query ? Faraday::Utils.parse_nested_query(query) : {} super(host, path, params, headers, body, block) end
Public Instance Methods
headers_match?(request_headers)
click to toggle source
# File lib/faraday/adapter/test.rb, line 170 def headers_match?(request_headers) headers.keys.all? do |key| request_headers[key] == headers[key] end end
matches?(request_host, request_uri, request_headers, request_body)
click to toggle source
# File lib/faraday/adapter/test.rb, line 141 def matches?(request_host, 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 (host.nil? || host == request_host) && 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 164 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 156 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 176 def to_s "#{path} #{body}" end