|
66 | 66 | expect(printed).to eq(msg) |
67 | 67 | end |
68 | 68 |
|
69 | | - context "when silenced" do |
| 69 | + context "when one token" do |
70 | 70 | subject(:printed) do |
71 | 71 | capture(:stderr) do |
72 | 72 | target |
73 | 73 | end |
74 | 74 | end |
75 | 75 |
|
| 76 | + let(:hash) do |
| 77 | + { |
| 78 | + access_token: token, |
| 79 | + } |
| 80 | + end |
| 81 | + |
76 | 82 | 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 |
80 | 85 | end |
81 | 86 |
|
82 | 87 | 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 |
85 | 100 | end |
86 | 101 | end |
87 | 102 |
|
| 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 | + |
88 | 112 | it "does not warn on STDERR" do |
89 | 113 | expect(printed).to eq("") |
90 | 114 | end |
|
122 | 146 | end |
123 | 147 | end |
124 | 148 |
|
125 | | - context "with no token keys" do |
| 149 | + context "with warning for no token keys" do |
126 | 150 | subject(:printed) do |
127 | 151 | capture(:stderr) do |
128 | 152 | target |
|
138 | 162 | OAuth2.config.silence_no_tokens_warning = @original_sntw |
139 | 163 | end |
140 | 164 |
|
| 165 | + let(:options) { {raise_errors: true} } |
| 166 | + |
141 | 167 | let(:hash) do |
142 | 168 | { |
143 | 169 | blather: "confusing bug here", |
144 | 170 | rather: token, |
145 | 171 | } |
146 | 172 | end |
147 | 173 |
|
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 |
152 | 175 | block_is_expected.to raise_error(OAuth2::Error) |
153 | 176 | 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 |
154 | 188 | end |
155 | 189 | end |
156 | 190 |
|
|
0 commit comments