test = Faraday::Connection.new do
use Faraday::Adapter::Test do |stub| stub.get '/nigiri/sake.json' do [200, {}, 'hi world'] end end
end
resp = test.get ‘/nigiri/sake.json’ resp.body # => ‘hi world’
# File lib/faraday/adapter/test.rb, line 144 def call(env) super normalized_path = Faraday::Utils.normalize_path(env[:url]) params_encoder = env.request.params_encoder || Faraday::Utils.default_params_encoder if stub = stubs.match(env[:method], normalized_path, env.request_headers, env[:body]) env[:params] = (query = env[:url].query) ? params_encoder.decode(query) : {} status, headers, body = stub.block.call(env) save_response(env, status, body, headers) else raise Stubs::NotFound, "no stubbed request for #{env[:method]} #{normalized_path} #{env[:body]}" end @app.call(env) end
Generated with the Darkfish Rdoc Generator 2.