class Faraday::Adapter::Test::Stubs
def delete(path, headers = {}, &block)
def delete(path, headers = {}, &block) new_stub(:delete, path, headers, &block) end
def empty?
def empty? @stack.empty? end
def get(path, headers = {}, &block)
def get(path, headers = {}, &block) new_stub(:get, path, headers, &block) end
def head(path, headers = {}, &block)
def head(path, headers = {}, &block) new_stub(:head, path, headers, &block) end
def initialize
def initialize # {:get => [Stub, Stub]} @stack, @consumed = {}, {} yield(self) if block_given? end
def match(request_method, path, headers, body)
def match(request_method, path, headers, body) return false if !@stack.key?(request_method) stack = @stack[request_method] consumed = (@consumed[request_method] ||= []) stub, meta = matches?(stack, path, headers, body) if stub consumed << stack.delete(stub) return stub, meta end matches?(consumed, path, headers, body) end
def matches?(stack, path, headers, body)
def matches?(stack, path, headers, body) stack.each do |stub| match_result, meta = stub.matches?(path, headers, body) return stub, meta if match_result end nil end
def new_stub(request_method, path, headers = {}, body=nil, &block)
def new_stub(request_method, path, headers = {}, body=nil, &block) normalized_path = path.is_a?(Regexp) ? path : Faraday::Utils.normalize_path(path) (@stack[request_method] ||= []) << Stub.new(normalized_path, headers, body, block) end
def options(path, headers = {}, &block)
def options(path, headers = {}, &block) new_stub(:options, path, headers, &block) end
def patch(path, body=nil, headers = {}, &block)
def patch(path, body=nil, headers = {}, &block) new_stub(:patch, path, headers, body, &block) end
def post(path, body=nil, headers = {}, &block)
def post(path, body=nil, headers = {}, &block) new_stub(:post, path, headers, body, &block) end
def put(path, body=nil, headers = {}, &block)
def put(path, body=nil, headers = {}, &block) new_stub(:put, path, headers, body, &block) end
def verify_stubbed_calls
def verify_stubbed_calls failed_stubs = [] @stack.each do |method, stubs| unless stubs.size == 0 failed_stubs.concat(stubs.map {|stub| "Expected #{method} #{stub}." }) end end raise failed_stubs.join(" ") unless failed_stubs.size == 0 end