Using Faraday for testing

# It's possible to define stubbed request outside a test adapter block.
stubs =Faraday::Adapter::Test::Stubs.newdo |stub|
stub.get('/tamago') { [200, {}, 'egg'] }
end# You can pass stubbed request to the test adapter or define them in a block# or a combination of the two.
test =Faraday.newdo |builder|
builder.adapter :test, stubs do |stub|
stub.get('/ebi') {[ 200, {}, 'shrimp' ]}
endend# It's also possible to stub additional requests after the connection has# been initialized. This is useful for testing.
stubs.get('/uni') {[ 200, {}, 'urchin' ]}
resp = test.get '/tamago'
resp.body # => 'egg'
resp = test.get '/ebi'
resp.body # => 'shrimp'
resp = test.get '/uni'
resp.body # => 'urchin'
resp = test.get '/else'#=> raises "no such stub" error# If you like, you can treat your stubs as mocks by verifying that all of# the stubbed calls were made. NOTE that this feature is still fairly# experimental: It will not verify the order or count of any stub, only that# it was called once during the course of the test.
stubs.verify_stubbed_calls

TODO

support streaming requests/responses

better stubbing API

Contributing

You can run the test suite against a live server by running script/test. It
automatically starts a test server in background. Only tests in
test/adapters/*_test.rb require a server, though.

Supported Ruby versions

If something doesn't work on one of these interpreters, it should be considered
a bug.

This library may inadvertently work (or seem to work) on other Ruby
implementations, however support will only be provided for the versions listed
above.

If you would like this library to support another Ruby version, you may
volunteer to be a maintainer. Being a maintainer entails making sure all tests
run and pass on that implementation. When something breaks on your
implementation, you will be personally responsible for providing patches in a
timely fashion. If critical issues for a particular implementation exist at the
time of a major release, support for that Ruby version may be dropped.