mirror of
https://github.com/lostisland/faraday.git
synced 2025-11-27 00:04:03 -05:00
Fix test order dependency in default_connection proxy test (#929)
* Fix the default_connection proxy test The assignment to the mock connection: `Faraday.default_connection = mock_connection` was persisting throughout the tests. If the random number generator is unlucky the following error occurs: \#<Double "Connection"> was originally created in one example but has leaked into another example and can no longer be used. rspec-mocks' doubles are designed to only last for one example, and you need to create a new one in each example you wish to use it for. This commit fixes the issue by explicitly setting the default_connection back to nil in an "after" block after the tests have run. Subsequent calls to `default_connection` within the test suite then behave as previously expected irrespective of the random test ordering.
This commit is contained in:
parent
c5ceb2679c
commit
dbba0734d6
@ -6,23 +6,26 @@ RSpec.describe Faraday do
|
||||
end
|
||||
|
||||
context 'proxies to default_connection' do
|
||||
it 'proxies methods that exist on the default_connection' do
|
||||
mock_conection = double('Connection')
|
||||
Faraday.default_connection = mock_conection
|
||||
let(:mock_connection) { double('Connection') }
|
||||
before do
|
||||
Faraday.default_connection = mock_connection
|
||||
end
|
||||
|
||||
expect(mock_conection).to receive(:this_should_be_proxied)
|
||||
it 'proxies methods that exist on the default_connection' do
|
||||
expect(mock_connection).to receive(:this_should_be_proxied)
|
||||
|
||||
Faraday.this_should_be_proxied
|
||||
end
|
||||
|
||||
it 'uses method_missing on Farady if there is no proxyable method' do
|
||||
mock_conection = double('Connection')
|
||||
Faraday.default_connection = mock_conection
|
||||
|
||||
it 'uses method_missing on Faraday if there is no proxyable method' do
|
||||
expect { Faraday.this_method_does_not_exist }.to raise_error(
|
||||
NoMethodError,
|
||||
"undefined method `this_method_does_not_exist' for Faraday:Module"
|
||||
)
|
||||
end
|
||||
|
||||
after do
|
||||
Faraday.default_connection = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user