From 6d73c89f733e393eba32ad2637eff54009aedd59 Mon Sep 17 00:00:00 2001 From: Geoff Hubbard Date: Mon, 4 Mar 2019 20:02:59 +0000 Subject: [PATCH] chore: RuboCop lint Style/MethodMissingSuper --- .rubocop_todo.yml | 5 ----- lib/faraday.rb | 6 +++++- spec/faraday_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0d726656a..d52aea8a1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/lib/faraday.rb b/lib/faraday.rb index f8d5191d4..c7d96610c 100644 --- a/lib/faraday.rb +++ b/lib/faraday.rb @@ -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 diff --git a/spec/faraday_spec.rb b/spec/faraday_spec.rb index 446fb3383..d0521ac2e 100644 --- a/spec/faraday_spec.rb +++ b/spec/faraday_spec.rb @@ -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