class Faraday::Adapter::Test

@example

test = Faraday::Connection.new do
  use Faraday::Adapter::Test do |stub|
    # Define matcher to match the request
    stub.get '/resource.json' do
      # return static content
      [200, {'Content-Type' => 'application/json'}, 'hi world']
    end

    # response with content generated based on request
    stub.get '/showget' do |env|
      [200, {'Content-Type' => 'text/plain'}, env[:method].to_s]
    end

    # A regular expression can be used as matching filter
    stub.get /\A\/items\/(\d+)\z/ do |env, meta|
      # in case regular expression is used, an instance of MatchData
      # can be received
      [200,
       {'Content-Type' => 'text/plain'},
       "showing item: #{meta[:match_data][1]}"
      ]
    end

   # Test the request body is the same as the stubbed body
   stub.post('/bar', 'name=YK&word=call') { [200, {}, ''] }

   # You can pass a proc as a stubbed body and check the request body in your way.
   # In this case, the proc should return true or false.
   stub.post('/foo', ->(request_body) do
     JSON.parse(request_body).slice('name') == { 'name' => 'YK' } }) { [200, {}, '']
   end

    # You can set strict_mode to exactly match the stubbed requests.
    stub.strict_mode = true
  end
end

resp = test.get '/resource.json'
resp.body # => 'hi world'

resp = test.get '/showget'
resp.body # => 'get'

resp = test.get '/items/1'
resp.body # => 'showing item: 1'

resp = test.get '/items/2'
resp.body # => 'showing item: 2'

resp = test.post '/bar', 'name=YK&word=call'
resp.status # => 200

resp = test.post '/foo', JSON.dump(name: 'YK', created_at: Time.now)
resp.status # => 200