class MnoeFaradayTestAdapter
Adapter and modified from: github.com/lostisland/faraday/blob/master/lib/faraday/adapter/test.rb
test = Faraday::Connection.new do
use MnoeFaradayTestAdapter do |stub| stub.get '/nigiri/sake.json' do [200, {}, 'hi world'] end end
end
resp = test.get '/nigiri/sake.json' resp.body # => 'hi world'
Attributes
stubs[RW]
Public Class Methods
new(app, stubs=nil, &block)
click to toggle source
Calls superclass method
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 147 def initialize(app, stubs=nil, &block) super(app) @stubs = stubs || Stubs.new configure(&block) if block end
Public Instance Methods
call(env)
click to toggle source
Calls superclass method
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 157 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
configure() { |stubs| ... }
click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 153 def configure yield(stubs) end