New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing page for new documentation #997
Comments
Thank you for bringing this up. In response, I have posted a PR to include live test/unit and rspec examples of using the Faraday Test adapter: #1000. This is the recommended way to test Faraday, instead of external test double libraries (rspec, mocha, webmock, etc). |
I noticed at no point is it testing things such as timeouts, connection errors, etc. Is the subject frowned upon, or just the way PR #998 uses. I suppose I don't get the syntax |
Oof, maybe I should revisit the Faraday test docs again :/ The syntax in #1000 uses a it 'parses name' do
# this block yields a rack response: an array with:
# response status, http header hash, and response body
stubs.get('/ebi') do |env|
[
200,
{ 'Content-Type': 'application/javascript' },
'{"name": "shrimp"}'
]
end
expect(client.sushi('ebi')).to eq('shrimp')
stubs.verify_stubbed_calls
end I apologize, I obviously didn't read your issues thoroughly enough. I totally missed that you specifically wanted to test exceptions. A test like this works too (which I will add to #1000): it 'handles exception' do
stubs.get('/ebi') do
raise Faraday::ConnectionFailed, nil
end
expect { client.sushi('ebi') }.to raise_error(Faraday::ConnectionFailed)
stubs.verify_stubbed_calls
end I prefer specific test double implementations like this to the more generalized mocking approach, as they still go through the entire Faraday request workflow. If a developer wants to use RSpec mocks anyway, then they'll be better served with the excellent RSpec documentation. |
Delivered with #1000 |
Basic Info
Issue description
There is no documentation on testing with Faraday. Where I work Ruby on Rails was introduced because it's cool. Little thought was given to testing red-cases. I'd like to contribute some documentation to help others
Steps to reproduce
usage
The text was updated successfully, but these errors were encountered: