pftg
9/11/2012 - 7:24 AM

Rails Isolation snippet with Faraday

Rails Isolation snippet with Faraday

#lib/client.rb

require 'faraday_middleware'

module Client
  def connection
    @connection ||= Faraday.new url: APP_URL do |faraday|

=begin
      Some Faraday Builder's code
      ...
=end

      faraday.adapter *Faraday.default_adapter
    end
  end
end
#config/initializers/faraday_stubs.rb
require 'faraday'

stubs = Faraday::Adapter::Test::Stubs.new do |stub|
  stub.get('/resources') {
    [200, { }, { resources: Stubs::Resources }]
  }
end

Faraday.default_adapter = [:test, stubs]