diff --git a/lib/fbe/octo.rb b/lib/fbe/octo.rb index ee0ce178..9446cffd 100644 --- a/lib/fbe/octo.rb +++ b/lib/fbe/octo.rb @@ -265,6 +265,10 @@ def with_disable_auto_paginate # rubocop:disable Layout/EmptyLineBetweenDefs o = intercepted(o) do |e, m, args, _r| next unless e == :before + unless client.respond_to?(m) + kind = options.testing.nil? ? Octokit::Client : Fbe::FakeOctokit + raise(NoMethodError.new("undefined method '#{m}' for an instance of #{kind}", m, args)) + end next if %i[off_quota? print_trace! rate_limit rate_limit!].include?(m) next if m == :get && %w[/rate_limit rate_limit].include?(args.first) if Fbe::SEARCH_METHODS.include?(m) diff --git a/test/fbe/test_octo.rb b/test/fbe/test_octo.rb index 9efa8b8a..c53d5aa7 100644 --- a/test/fbe/test_octo.rb +++ b/test/fbe/test_octo.rb @@ -189,6 +189,22 @@ def test_fails_user_request_when_off_quota assert_raises(StandardError) { o.user(42) } end + def test_raises_no_method_error_for_a_missing_method + WebMock.disable_net_connect! + stub_request(:get, 'https://api.github.com/rate_limit').to_return( + { body: '{}', headers: { 'X-RateLimit-Remaining' => '4000' } } + ) + { + { 'testing' => true } => 'Fbe::FakeOctokit', + { 'github_token' => 'fake-token' } => 'Octokit::Client' + }.each do |opts, kind| + o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new(opts)) + e = assert_raises(NoMethodError) { o.no_such_method('foo/bar') } + assert_equal(:no_such_method, e.name, "wrong method name in #{e.message.inspect}") + assert_includes(e.message, kind, "the client class is not named in #{e.message.inspect}") + end + end + def test_rate_limit_bang_works_when_off_quota WebMock.disable_net_connect! stub_request(:get, 'https://api.github.com/rate_limit').to_return(