class Faraday::Adapter::Test::Stubs

def delete(path, &block)

def delete(path, &block)
  new_stub(:delete, path, &block)
end

def empty?

def empty?
  @stack.empty?
end

def get(path, &block)

def get(path, &block)
  new_stub(:get, path, &block)
end

def head(path, &block)

def head(path, &block)
  new_stub(:head, path, &block)
end

def initialize

def initialize
  # {:get => [Stub, Stub]}
  @stack, @consumed = {}, {}
  yield self if block_given?
end

def match(request_method, path, body)

def match(request_method, path, body)
  return false if !@stack.key?(request_method)
  stack = @stack[request_method]
  consumed = (@consumed[request_method] ||= [])
  if stub = matches?(stack, path, body)
    consumed << stack.delete(stub)
    stub
  else
    matches?(consumed, path, body)
  end
end

def matches?(stack, path, body)

def matches?(stack, path, body)
  stack.detect { |stub| stub.matches?(path, body) }
end

def new_stub(request_method, path, body=nil, &block)

def new_stub(request_method, path, body=nil, &block)
  (@stack[request_method] ||= []) << Stub.new(path, body, block)
end

def post(path, body=nil, &block)

def post(path, body=nil, &block)
  new_stub(:post, path, body, &block)
end

def put(path, body=nil, &block)

def put(path, body=nil, &block)
  new_stub(:put, path, body, &block)
end

def verify_stubbed_calls

Raises an error if any of the stubbed calls have not been made.
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