Skip to content

Instantly share code, notes, and snippets.

@afbroman
Forked from anonymous/faraday_stubbing
Created June 3, 2016 15:10
Show Gist options
  • Save afbroman/c88717c19c6e376bae05ee614238c6b2 to your computer and use it in GitHub Desktop.
Save afbroman/c88717c19c6e376bae05ee614238c6b2 to your computer and use it in GitHub Desktop.
Stubbing with Faraday
def stub_request
faraday_stub = Faraday.new do |builder|
builder.adapter :test do |stub|
stub.post('/api/service', {id: '111', data: {'a': 1}}) {|env| [200, {}, mock_response]}
stub.get('/api/another_service', {query: 'foo'}) {|env| [200, {}, second_mock_response]}
end
end
Service::Something.stubs(:connection).returns(faraday_stub)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment