Skip to content

Commit 37aebbd

Browse files
committed
✨ silence_no_tokens_warning
1 parent 5231b9e commit 37aebbd

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

spec/oauth2/access_token_spec.rb

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,49 @@
6666
expect(printed).to eq(msg)
6767
end
6868

69-
context "when silenced" do
69+
context "when one token" do
7070
subject(:printed) do
7171
capture(:stderr) do
7272
target
7373
end
7474
end
7575

76+
let(:hash) do
77+
{
78+
access_token: token,
79+
}
80+
end
81+
7682
before do
77-
OAuth2.configure do |config|
78-
config.silence_extra_tokens_warning = true
79-
end
83+
@original_setw = OAuth2.config.silence_extra_tokens_warning
84+
OAuth2.config.silence_extra_tokens_warning = false
8085
end
8186

8287
after do
83-
OAuth2.configure do |config|
84-
config.silence_extra_tokens_warning = false
88+
OAuth2.config.silence_extra_tokens_warning = @original_setw
89+
end
90+
91+
it "does not warn on STDERR" do
92+
expect(printed).to eq("")
93+
end
94+
end
95+
96+
context "when silenced" do
97+
subject(:printed) do
98+
capture(:stderr) do
99+
target
85100
end
86101
end
87102

103+
before do
104+
@original_setw = OAuth2.config.silence_extra_tokens_warning
105+
OAuth2.config.silence_extra_tokens_warning = true
106+
end
107+
108+
after do
109+
OAuth2.config.silence_extra_tokens_warning = @original_setw
110+
end
111+
88112
it "does not warn on STDERR" do
89113
expect(printed).to eq("")
90114
end
@@ -122,7 +146,7 @@
122146
end
123147
end
124148

125-
context "with no token keys" do
149+
context "with warning for no token keys" do
126150
subject(:printed) do
127151
capture(:stderr) do
128152
target
@@ -138,19 +162,29 @@
138162
OAuth2.config.silence_no_tokens_warning = @original_sntw
139163
end
140164

165+
let(:options) { {raise_errors: true} }
166+
141167
let(:hash) do
142168
{
143169
blather: "confusing bug here",
144170
rather: token,
145171
}
146172
end
147173

148-
it "warns on STDERR and selects the correct key" do
149-
msg = <<-MSG.lstrip
150-
OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key ([:access_token, :id_token]); using :access_token.
151-
MSG
174+
it "raises an error" do
152175
block_is_expected.to raise_error(OAuth2::Error)
153176
end
177+
178+
context "when not raising errors" do
179+
let(:options) { {raise_errors: false} }
180+
181+
it "warns on STDERR and selects the correct key" do
182+
msg = <<-MSG.lstrip
183+
OAuth2::AccessToken has no token
184+
MSG
185+
expect(printed).to eq(msg)
186+
end
187+
end
154188
end
155189
end
156190

spec/oauth2_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

33
RSpec.describe OAuth2 do
4-
it "silence_extra_tokens_warning default is opposite of OAUTH_DEBUG" do
5-
expect(described_class.config.silence_extra_tokens_warning).to be(true)
4+
it "silence_extra_tokens_warning is a boolean" do
5+
expect(described_class.config.silence_extra_tokens_warning).to be(true).or be(false)
66
end
77

88
describe ".configure" do

0 commit comments

Comments
 (0)