Skip to content

Instantly share code, notes, and snippets.

@pftg
Created September 11, 2012 07:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pftg/3696658 to your computer and use it in GitHub Desktop.
Save pftg/3696658 to your computer and use it in GitHub Desktop.
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment