class Faraday::Adapter::Test::Stub
rubocop:disable Style/StructInheritance
Stub request
def body_match?(request_body)
def body_match?(request_body) return true if body.to_s.empty? case body when Proc body.call(request_body) else request_body == body end end
def headers_match?(request_headers)
def headers_match?(request_headers) if strict_mode headers_with_user_agent = headers.dup.tap do |hs| # NOTE: Set User-Agent in case it's not set when creating Stubs. # Users would not want to set Faraday's User-Agent explicitly. hs[:user_agent] ||= Connection::USER_AGENT end return Set.new(headers_with_user_agent) == Set.new(request_headers) end headers.keys.all? do |key| request_headers[key] == headers[key] end end
def matches?(env)
-
env
(Faraday::Env
) --
def matches?(env) request_host = env[:url].host request_path = Faraday::Utils.normalize_path(env[:url].path) request_headers = env.request_headers request_body = env[:body] # meta is a hash used as carrier # that will be yielded to consumer block meta = {} [(host.nil? || host == request_host) && path_match?(request_path, meta) && params_match?(env) && body_match?(request_body) && headers_match?(request_headers), meta] end
def params_match?(env)
-
env
(Faraday::Env
) --
def params_match?(env) request_params = env[:params] params = env.params_encoder.decode(query) || {} if strict_mode return Set.new(params) == Set.new(request_params) end params.keys.all? do |key| request_params[key] == params[key] end end
def path_match?(request_path, meta)
def path_match?(request_path, meta) if path.is_a?(Regexp) !!(meta[:match_data] = path.match(request_path)) else path == request_path end end
def to_s
def to_s "#{path} #{body}" end