Skip to content

Commit 3e3e84d

Browse files
committed
✨ OAuth2::OAUTH_DEBUG
1 parent 8434f5a commit 3e3e84d

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

.rubocop_gradual.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[66, 5, 20, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 2485198147],
44
[78, 5, 74, "Style/InvertibleUnlessCondition: Prefer `if Gem.rubygems_version >= Gem::Version.new(\"2.7.0\")` over `unless Gem.rubygems_version < Gem::Version.new(\"2.7.0\")`.", 2453573257]
55
],
6-
"lib/oauth2.rb:3930909031": [
7-
[31, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
8-
[34, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
6+
"lib/oauth2.rb:649414550": [
7+
[34, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
8+
[37, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
99
],
1010
"lib/oauth2/authenticator.rb:3711266135": [
1111
[42, 5, 113, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 734523108]
@@ -41,26 +41,26 @@
4141
[69, 15, 38, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1480816240],
4242
[79, 13, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2314399065]
4343
],
44-
"spec/oauth2/client_spec.rb:824695973": [
44+
"spec/oauth2/client_spec.rb:2242285093": [
4545
[6, 1, 29, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/client*_spec.rb`.", 439549885],
4646
[174, 7, 492, "RSpec/NoExpectationExample: No expectation found in this example.", 1272021224],
4747
[193, 7, 592, "RSpec/NoExpectationExample: No expectation found in this example.", 3428877205],
4848
[206, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2320605227],
4949
[221, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1276531672],
5050
[236, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1383956904],
5151
[251, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3376202107],
52-
[869, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
53-
[878, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
54-
[889, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
55-
[934, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
56-
[979, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
57-
[983, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
58-
[991, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
59-
[1079, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
60-
[1083, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
61-
[1163, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
62-
[1188, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
63-
[1198, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
52+
[867, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
53+
[876, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
54+
[887, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
55+
[932, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
56+
[977, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
57+
[981, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
58+
[989, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
59+
[1077, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
60+
[1081, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
61+
[1161, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
62+
[1186, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
63+
[1196, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
6464
],
6565
"spec/oauth2/error_spec.rb:1209122273": [
6666
[23, 1, 28, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/error*_spec.rb`.", 3385870076],
@@ -97,7 +97,7 @@
9797
"spec/oauth2/version_spec.rb:1001406821": [
9898
[3, 1, 30, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/version*_spec.rb`.", 1099517182]
9999
],
100-
"spec/oauth2_spec.rb:1511642301": [
100+
"spec/oauth2_spec.rb:438638294": [
101101
[3, 1, 21, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2*_spec.rb`.", 3359091140],
102102
[5, 68, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785]
103103
]

lib/oauth2.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
# The namespace of this library
2727
module OAuth2
28-
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(silence_extra_tokens_warning: false)
28+
OAUTH_DEBUG = ENV.fetch("OAUTH_DEBUG", "false").casecmp("true").zero?
29+
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(
30+
silence_extra_tokens_warning: !OAUTH_DEBUG,
31+
)
2932
@config = DEFAULT_CONFIG.dup
3033
class << self
3134
attr_accessor :config

lib/oauth2/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def build_access_token_legacy(response, access_token_opts, extract_access_token)
449449
end
450450

451451
def oauth_debug_logging(builder)
452-
builder.response(:logger, options[:logger], bodies: true) if ENV["OAUTH_DEBUG"] == "true"
452+
builder.response(:logger, options[:logger], bodies: true) if OAUTH_DEBUG
453453
end
454454
end
455455
end

spec/oauth2/client_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@
267267

268268
describe "#connection" do
269269
context "when debugging" do
270-
include_context "with stubbed env"
271270
before do
272-
stub_env("OAUTH_DEBUG" => debug_value)
271+
stub_const("OAuth2::OAUTH_DEBUG", debug_value)
273272
end
274273

275274
context "when OAUTH_DEBUG=true" do
276-
let(:debug_value) { "true" }
275+
let(:debug_value) { true }
277276

278277
it "smoothly handles successive requests" do
279278
silence_all do
@@ -301,7 +300,7 @@
301300
end
302301

303302
context "when OAUTH_DEBUG=false" do
304-
let(:debug_value) { "false" }
303+
let(:debug_value) { false }
305304

306305
it "smoothly handles successive requests" do
307306
silence_all do
@@ -358,10 +357,9 @@
358357
end
359358

360359
context "with ENV" do
361-
include_context "with stubbed env"
362360
context "when OAUTH_DEBUG=true" do
363361
before do
364-
stub_env("OAUTH_DEBUG" => "true")
362+
stub_const("OAuth2::OAUTH_DEBUG", true)
365363
end
366364

367365
it "outputs to $stdout when OAUTH_DEBUG=true" do

spec/oauth2_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe OAuth2 do
44
it "has a default config for silence_extra_tokens_warning" do
5-
expect(described_class.config.silence_extra_tokens_warning).to eq(false)
5+
expect(described_class.config.silence_extra_tokens_warning).to eq(true)
66
end
77

88
describe ".configure" do

0 commit comments

Comments
 (0)