chore: RuboCop lint Style/MethodMissingSuper (#928)

This commit is contained in:
Geoff Hubbard 2019-03-04 22:07:33 +01:00 committed by Mattia
parent 6b0eb71322
commit c5ceb2679c
3 changed files with 26 additions and 6 deletions

View File

@ -76,11 +76,6 @@ Style/GuardClause:
- 'lib/faraday/request/url_encoded.rb'
- 'lib/faraday/utils/headers.rb'
# Offense count: 1
Style/MethodMissingSuper:
Exclude:
- 'lib/faraday.rb'
# Offense count: 1
Style/MissingRespondToMissing:
Exclude:

View File

@ -111,7 +111,11 @@ module Faraday
# Internal: Proxies method calls on the Faraday constant to
# .default_connection.
def method_missing(name, *args, &block)
default_connection.send(name, *args, &block)
if default_connection.respond_to?(name)
default_connection.send(name, *args, &block)
else
super
end
end
end

View File

@ -4,4 +4,25 @@ RSpec.describe Faraday do
it 'has a version number' do
expect(Faraday::VERSION).not_to be nil
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
expect(mock_conection).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
expect { Faraday.this_method_does_not_exist }.to raise_error(
NoMethodError,
"undefined method `this_method_does_not_exist' for Faraday:Module"
)
end
end
end