Skip to content
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

chore: RuboCop lint Style/MethodMissingSuper #928

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Expand Up @@ -82,11 +82,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:
Expand Down
6 changes: 5 additions & 1 deletion lib/faraday.rb
Expand Up @@ -111,7 +111,11 @@ def respond_to?(symbol, include_private = false)
# 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

Expand Down
21 changes: 21 additions & 0 deletions spec/faraday_spec.rb
Expand Up @@ -4,4 +4,25 @@
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