Skip to content

Commit a62de00

Browse files
committed
✅ 100% branch coverage
1 parent 18e01d7 commit a62de00

File tree

2 files changed

+93
-28
lines changed

2 files changed

+93
-28
lines changed

.rubocop_gradual.lock

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
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:3563577000": [
7-
[34, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
8-
[37, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
6+
"lib/oauth2.rb:1956148869": [
7+
[35, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
8+
[38, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
9+
],
10+
"lib/oauth2/access_token.rb:2233632404": [
11+
[49, 13, 5, "Style/IdenticalConditionalBranches: Move `t_key` out of the conditional.", 183811513],
12+
[55, 13, 5, "Style/IdenticalConditionalBranches: Move `t_key` out of the conditional.", 183811513]
913
],
1014
"lib/oauth2/authenticator.rb:3711266135": [
1115
[42, 5, 113, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 734523108]
@@ -28,11 +32,11 @@
2832
[130, 3, 52, "Gemspec/DependencyVersion: Dependency version specification is required.", 3163430777],
2933
[131, 3, 48, "Gemspec/DependencyVersion: Dependency version specification is required.", 425065368]
3034
],
31-
"spec/oauth2/access_token_spec.rb:2406469319": [
35+
"spec/oauth2/access_token_spec.rb:3473606468": [
3236
[3, 1, 34, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/access_token*_spec.rb`.", 1972107547],
33-
[612, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
34-
[682, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],
35-
[686, 9, 79, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2507338967]
37+
[780, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
38+
[850, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],
39+
[854, 9, 79, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2507338967]
3640
],
3741
"spec/oauth2/authenticator_spec.rb:853320290": [
3842
[3, 1, 36, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/authenticator*_spec.rb`.", 819808017],
@@ -41,26 +45,26 @@
4145
[69, 15, 38, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1480816240],
4246
[79, 13, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2314399065]
4347
],
44-
"spec/oauth2/client_spec.rb:623759711": [
48+
"spec/oauth2/client_spec.rb:2085440011": [
4549
[6, 1, 29, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/client*_spec.rb`.", 439549885],
4650
[174, 7, 492, "RSpec/NoExpectationExample: No expectation found in this example.", 1272021224],
4751
[193, 7, 592, "RSpec/NoExpectationExample: No expectation found in this example.", 3428877205],
4852
[206, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2320605227],
4953
[221, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1276531672],
5054
[236, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1383956904],
5155
[251, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3376202107],
52-
[865, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
53-
[874, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
54-
[885, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
55-
[930, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
56-
[975, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
57-
[979, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
58-
[987, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
59-
[1075, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
60-
[1079, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
61-
[1159, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
62-
[1184, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
63-
[1194, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
56+
[829, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
57+
[838, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
58+
[849, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
59+
[894, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
60+
[939, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
61+
[943, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
62+
[951, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
63+
[1039, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
64+
[1043, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
65+
[1123, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
66+
[1148, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
67+
[1158, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
6468
],
6569
"spec/oauth2/error_spec.rb:1209122273": [
6670
[23, 1, 28, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/error*_spec.rb`.", 3385870076],
@@ -97,7 +101,7 @@
97101
"spec/oauth2/version_spec.rb:1001406821": [
98102
[3, 1, 30, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/version*_spec.rb`.", 1099517182]
99103
],
100-
"spec/oauth2_spec.rb:2292862590": [
104+
"spec/oauth2_spec.rb:4211477230": [
101105
[3, 1, 21, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2*_spec.rb`.", 3359091140]
102106
]
103107
}

spec/oauth2/access_token_spec.rb

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,18 @@
185185
expect(printed).to eq(msg)
186186
end
187187

188-
context "when custom token_name" do
188+
context "when custom token_name valid" do
189189
let(:options) { {raise_errors: false} }
190190

191191
let(:hash) do
192192
{
193193
"lollipop" => token,
194-
expires_at: Time.now.to_i + 200,
195-
foo: "bar",
196-
header_format: "Bearer %",
197-
mode: :header,
198-
param_name: "lollipop",
199-
token_name: "lollipop",
194+
:expires_at => Time.now.to_i + 200,
195+
:foo => "bar",
196+
:header_format => "Bearer %",
197+
:mode => :header,
198+
:param_name => "lollipop",
199+
:token_name => "lollipop",
200200
}
201201
end
202202

@@ -208,6 +208,67 @@
208208
expect(printed).to eq("")
209209
end
210210
end
211+
212+
context "when custom token_name invalid" do
213+
let(:options) { {raise_errors: false} }
214+
215+
let(:hash) do
216+
{
217+
"babyshark" => token,
218+
:expires_at => Time.now.to_i + 200,
219+
:foo => "bar",
220+
:header_format => "Bearer %",
221+
:mode => :header,
222+
:param_name => "lollipop",
223+
:token_name => "lollipop",
224+
}
225+
end
226+
227+
context "when silence_no_tokens_warning is false" do
228+
before do
229+
@original_sntw = OAuth2.config.silence_no_tokens_warning
230+
OAuth2.config.silence_no_tokens_warning = false
231+
end
232+
233+
after do
234+
OAuth2.config.silence_no_tokens_warning = @original_sntw
235+
end
236+
237+
it "finds no token" do
238+
expect(target.token).to eq("")
239+
end
240+
241+
it "warns when no token is found" do
242+
expect(printed.each_line.to_a).to eq([
243+
"\n",
244+
"OAuth2::AccessToken#from_hash key mismatch.\n",
245+
%{Custom token_name (lollipop) is not found in (["babyshark", :expires_at, :foo, :header_format, :mode, :param_name, :token_name])\n},
246+
"You may need to set `snaky: false`. See inline documentation for more info.\n",
247+
" \n",
248+
"OAuth2::AccessToken has no token\n",
249+
])
250+
end
251+
end
252+
253+
context "when silence_no_tokens_warning is true" do
254+
before do
255+
@original_sntw = OAuth2.config.silence_no_tokens_warning
256+
OAuth2.config.silence_no_tokens_warning = true
257+
end
258+
259+
after do
260+
OAuth2.config.silence_no_tokens_warning = @original_sntw
261+
end
262+
263+
it "finds no token" do
264+
expect(target.token).to eq("")
265+
end
266+
267+
it "does not warn when no token is found" do
268+
expect(printed.each_line.to_a).to eq([])
269+
end
270+
end
271+
end
211272
end
212273
end
213274
end

0 commit comments

Comments
 (0)