yt 0.32.4 → 0.33.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -4
  3. data/CHANGELOG.md +43 -2
  4. data/README.md +22 -33
  5. data/YOUTUBE_IT.md +4 -4
  6. data/bin/yt +2 -9
  7. data/lib/yt.rb +0 -1
  8. data/lib/yt/actions/list.rb +1 -1
  9. data/lib/yt/associations/has_reports.rb +9 -14
  10. data/lib/yt/collections/playlist_items.rb +10 -1
  11. data/lib/yt/collections/reports.rb +5 -7
  12. data/lib/yt/models/account.rb +21 -1
  13. data/lib/yt/models/asset.rb +10 -1
  14. data/lib/yt/models/channel.rb +2 -5
  15. data/lib/yt/models/content_owner.rb +20 -0
  16. data/lib/yt/models/match_policy.rb +4 -6
  17. data/lib/yt/models/playlist.rb +12 -2
  18. data/lib/yt/models/playlist_item.rb +8 -1
  19. data/lib/yt/models/resource.rb +69 -3
  20. data/lib/yt/models/statistics_set.rb +2 -1
  21. data/lib/yt/models/url.rb +2 -60
  22. data/lib/yt/models/video.rb +16 -3
  23. data/lib/yt/request.rb +6 -2
  24. data/lib/yt/version.rb +1 -1
  25. data/yt.gemspec +5 -2
  26. metadata +31 -169
  27. data/spec/collections/claims_spec.rb +0 -62
  28. data/spec/collections/comment_threads_spec.rb +0 -46
  29. data/spec/collections/playlist_items_spec.rb +0 -44
  30. data/spec/collections/playlists_spec.rb +0 -27
  31. data/spec/collections/policies_spec.rb +0 -30
  32. data/spec/collections/references_spec.rb +0 -30
  33. data/spec/collections/reports_spec.rb +0 -30
  34. data/spec/collections/subscriptions_spec.rb +0 -25
  35. data/spec/collections/videos_spec.rb +0 -43
  36. data/spec/constants/geography_spec.rb +0 -16
  37. data/spec/errors/forbidden_spec.rb +0 -10
  38. data/spec/errors/missing_auth_spec.rb +0 -24
  39. data/spec/errors/no_items_spec.rb +0 -10
  40. data/spec/errors/request_error_spec.rb +0 -44
  41. data/spec/errors/server_error_spec.rb +0 -10
  42. data/spec/errors/unauthorized_spec.rb +0 -10
  43. data/spec/models/account_spec.rb +0 -138
  44. data/spec/models/annotation_spec.rb +0 -180
  45. data/spec/models/asset_spec.rb +0 -32
  46. data/spec/models/channel_spec.rb +0 -127
  47. data/spec/models/claim_event_spec.rb +0 -62
  48. data/spec/models/claim_history_spec.rb +0 -27
  49. data/spec/models/claim_spec.rb +0 -223
  50. data/spec/models/comment_spec.rb +0 -40
  51. data/spec/models/comment_thread_spec.rb +0 -93
  52. data/spec/models/configuration_spec.rb +0 -44
  53. data/spec/models/content_detail_spec.rb +0 -52
  54. data/spec/models/content_owner_detail_spec.rb +0 -6
  55. data/spec/models/file_detail_spec.rb +0 -13
  56. data/spec/models/live_streaming_detail_spec.rb +0 -6
  57. data/spec/models/ownership_spec.rb +0 -59
  58. data/spec/models/player_spec.rb +0 -13
  59. data/spec/models/playlist_item_spec.rb +0 -120
  60. data/spec/models/playlist_spec.rb +0 -138
  61. data/spec/models/policy_rule_spec.rb +0 -63
  62. data/spec/models/policy_spec.rb +0 -41
  63. data/spec/models/rating_spec.rb +0 -12
  64. data/spec/models/reference_spec.rb +0 -249
  65. data/spec/models/request_spec.rb +0 -204
  66. data/spec/models/resource_spec.rb +0 -42
  67. data/spec/models/right_owner_spec.rb +0 -71
  68. data/spec/models/snippet_spec.rb +0 -13
  69. data/spec/models/statistics_set_spec.rb +0 -13
  70. data/spec/models/status_spec.rb +0 -13
  71. data/spec/models/subscription_spec.rb +0 -30
  72. data/spec/models/url_spec.rb +0 -78
  73. data/spec/models/video_category_spec.rb +0 -21
  74. data/spec/models/video_spec.rb +0 -669
  75. data/spec/requests/as_account/account_spec.rb +0 -143
  76. data/spec/requests/as_account/authentications_spec.rb +0 -127
  77. data/spec/requests/as_account/channel_spec.rb +0 -246
  78. data/spec/requests/as_account/channels_spec.rb +0 -18
  79. data/spec/requests/as_account/playlist_item_spec.rb +0 -55
  80. data/spec/requests/as_account/playlist_spec.rb +0 -218
  81. data/spec/requests/as_account/thumbnail.jpg +0 -0
  82. data/spec/requests/as_account/video.mp4 +0 -0
  83. data/spec/requests/as_account/video_spec.rb +0 -408
  84. data/spec/requests/as_content_owner/account_spec.rb +0 -29
  85. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +0 -15
  86. data/spec/requests/as_content_owner/asset_spec.rb +0 -31
  87. data/spec/requests/as_content_owner/bulk_report_job_spec.rb +0 -19
  88. data/spec/requests/as_content_owner/channel_spec.rb +0 -1836
  89. data/spec/requests/as_content_owner/claim_history_spec.rb +0 -20
  90. data/spec/requests/as_content_owner/claim_spec.rb +0 -17
  91. data/spec/requests/as_content_owner/content_owner_spec.rb +0 -370
  92. data/spec/requests/as_content_owner/match_policy_spec.rb +0 -17
  93. data/spec/requests/as_content_owner/ownership_spec.rb +0 -25
  94. data/spec/requests/as_content_owner/playlist_spec.rb +0 -767
  95. data/spec/requests/as_content_owner/video_group_spec.rb +0 -112
  96. data/spec/requests/as_content_owner/video_spec.rb +0 -1211
  97. data/spec/requests/as_server_app/channel_spec.rb +0 -54
  98. data/spec/requests/as_server_app/comment_spec.rb +0 -22
  99. data/spec/requests/as_server_app/comment_thread_spec.rb +0 -27
  100. data/spec/requests/as_server_app/comment_threads_spec.rb +0 -41
  101. data/spec/requests/as_server_app/playlist_item_spec.rb +0 -30
  102. data/spec/requests/as_server_app/playlist_spec.rb +0 -33
  103. data/spec/requests/as_server_app/url_spec.rb +0 -94
  104. data/spec/requests/as_server_app/video_spec.rb +0 -60
  105. data/spec/requests/as_server_app/videos_spec.rb +0 -40
  106. data/spec/requests/unauthenticated/video_spec.rb +0 -14
  107. data/spec/spec_helper.rb +0 -20
  108. data/spec/support/fail_matcher.rb +0 -15
  109. data/spec/support/global_hooks.rb +0 -48
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/policy_rule'
3
-
4
- describe Yt::PolicyRule do
5
- subject(:policy_rule) { Yt::PolicyRule.new data: data }
6
-
7
- describe '#action' do
8
- context 'given fetching a policy rule returns an action' do
9
- let(:data) { {"action"=>"takedown"} }
10
- it { expect(policy_rule.action).to eq 'takedown' }
11
- end
12
- end
13
-
14
- describe '#subaction' do
15
- context 'given fetching a policy rule returns a subaction' do
16
- let(:data) { {"subaction"=>"review"} }
17
- it { expect(policy_rule.subaction).to eq 'review' }
18
- end
19
- end
20
-
21
- describe '#included_territories' do
22
- context 'given fetching a policy rule returns included territories' do
23
- let(:data) { {"conditions"=>{"requiredTerritories"=>{"type"=>"include", "territories"=>["US", "CA"]}}} }
24
- let(:data) { {"conditions"=>{"requiredTerritories"=>{"type"=>"include", "territories"=>["US", "CA"]}}} }
25
- it { expect(policy_rule.included_territories).to eq %w(US CA) }
26
- end
27
- end
28
-
29
- describe '#excluded_territories' do
30
- context 'given fetching a policy rule returns excluded territories' do
31
- let(:data) { {"conditions"=>{"requiredTerritories"=>{"type"=>"exclude", "territories"=>["US", "CA"]}}} }
32
- it { expect(policy_rule.excluded_territories).to eq %w(US CA) }
33
- end
34
- end
35
-
36
- describe '#match_duration' do
37
- context 'given fetching a policy rule returns a match duration list' do
38
- let(:data) { {"conditions"=>{"matchDuration"=>[{"high"=>60.0}]}} }
39
- it { expect(policy_rule.match_duration).to match_array [{low: nil, high: 60.0}] }
40
- end
41
- end
42
-
43
- describe '#match_percent' do
44
- context 'given fetching a policy rule returns a match percent list' do
45
- let(:data) { {"conditions"=>{"matchPercent"=>[{"high"=>60.0}]}} }
46
- it { expect(policy_rule.match_percent).to match_array [{low: nil, high: 60.0}] }
47
- end
48
- end
49
-
50
- describe '#reference_duration' do
51
- context 'given fetching a policy rule returns a reference duration list' do
52
- let(:data) { {"conditions"=>{"referenceDuration"=>[{"low"=>60.0, "high"=>600.0}, {"low"=>20.0, "high"=>30.0}]}} }
53
- it { expect(policy_rule.reference_duration).to match_array [{low: 60.0, high: 600.0}, {low: 20.0, high: 30.0}] }
54
- end
55
- end
56
-
57
- describe '#reference_percent' do
58
- context 'given fetching a policy rule returns a reference percent list' do
59
- let(:data) { {"conditions"=>{"referencePercent"=>[{"low"=>60.0, "high"=>600.0}, {"low"=>20.0, "high"=>30.0}]}} }
60
- it { expect(policy_rule.reference_percent).to match_array [{low: 60.0, high: 600.0}, {low: 20.0, high: 30.0}] }
61
- end
62
- end
63
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/policy'
3
-
4
- describe Yt::Policy do
5
- subject(:policy) { Yt::Policy.new data: data }
6
-
7
- describe '#id' do
8
- context 'given fetching a policy returns an id' do
9
- let(:data) { {"id"=>"S123456789"} }
10
- it { expect(policy.id).to eq 'S123456789' }
11
- end
12
- end
13
-
14
- describe '#name' do
15
- context 'given fetching a policy returns a name' do
16
- let(:data) { {"name"=>"Block in all countries"} }
17
- it { expect(policy.name).to eq 'Block in all countries' }
18
- end
19
- end
20
-
21
- describe '#description' do
22
- context 'given fetching a policy returns a description' do
23
- let(:data) { {"description"=>"Block videos in every country"} }
24
- it { expect(policy.description).to eq 'Block videos in every country' }
25
- end
26
- end
27
-
28
- describe '#updated_at' do
29
- context 'given fetching a policy returns a timeUpdated' do
30
- let(:data) { {"timeUpdated"=>"1970-01-16T20:33:03.675Z"} }
31
- it { expect(policy.updated_at.year).to be 1970 }
32
- end
33
- end
34
-
35
- describe '#rules' do
36
- context 'given fetching a policy returns rules' do
37
- let(:data) { {"rules"=>[{"action"=>"track"},{"action"=>"track"}]} }
38
- it { expect(policy.rules.size).to be 2 }
39
- end
40
- end
41
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/rating'
3
-
4
- describe Yt::Rating do
5
- subject(:rating) { Yt::Rating.new }
6
-
7
- describe '#update' do
8
- before { expect(rating).to receive(:do_update).and_yield }
9
-
10
- it { expect{rating.set :like}.to change{rating.rating} }
11
- end
12
- end
@@ -1,249 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/reference'
3
-
4
- describe Yt::Reference do
5
- subject(:reference) { Yt::Reference.new data: data }
6
-
7
- describe '#id' do
8
- context 'given fetching a reference returns an id' do
9
- let(:data) { {"id"=>"aBcD1EfGHIk"} }
10
- it { expect(reference.id).to eq 'aBcD1EfGHIk' }
11
- end
12
- end
13
-
14
- describe '#asset_id' do
15
- context 'given fetching a reference returns an assetId' do
16
- let(:data) { {"assetId"=>"A123456789012601"} }
17
- it { expect(reference.asset_id).to eq 'A123456789012601' }
18
- end
19
- end
20
-
21
- describe '#status' do
22
- context 'given fetching a reference returns a status' do
23
- let(:data) { {"status"=>"active"} }
24
- it { expect(reference.status).to eq 'active' }
25
- end
26
- end
27
-
28
- describe '#activating?' do
29
- context 'given fetching a reference returns an activating status' do
30
- let(:data) { {"status"=>"activating"} }
31
- it { expect(reference).to be_activating }
32
- end
33
-
34
- context 'given fetching a reference does not return an activating status' do
35
- let(:data) { {"status"=>"unknown"} }
36
- it { expect(reference).not_to be_activating }
37
- end
38
- end
39
-
40
- describe '#active?' do
41
- context 'given fetching a reference returns an active status' do
42
- let(:data) { {"status"=>"active"} }
43
- it { expect(reference).to be_active }
44
- end
45
-
46
- context 'given fetching a reference does not return an active status' do
47
- let(:data) { {"status"=>"unknown"} }
48
- it { expect(reference).not_to be_active }
49
- end
50
- end
51
-
52
- describe '#checking?' do
53
- context 'given fetching a reference returns an checking status' do
54
- let(:data) { {"status"=>"checking"} }
55
- it { expect(reference).to be_checking }
56
- end
57
-
58
- context 'given fetching a reference does not return an checking status' do
59
- let(:data) { {"status"=>"unknown"} }
60
- it { expect(reference).not_to be_checking }
61
- end
62
- end
63
-
64
- describe '#computing_fingerprint?' do
65
- context 'given fetching a reference returns an computing_fingerprint status' do
66
- let(:data) { {"status"=>"computing_fingerprint"} }
67
- it { expect(reference).to be_computing_fingerprint }
68
- end
69
-
70
- context 'given fetching a reference does not return an computing_fingerprint status' do
71
- let(:data) { {"status"=>"unknown"} }
72
- it { expect(reference).not_to be_computing_fingerprint }
73
- end
74
- end
75
-
76
- describe '#deleted?' do
77
- context 'given fetching a reference returns an deleted status' do
78
- let(:data) { {"status"=>"deleted"} }
79
- it { expect(reference).to be_deleted }
80
- end
81
-
82
- context 'given fetching a reference does not return an deleted status' do
83
- let(:data) { {"status"=>"unknown"} }
84
- it { expect(reference).not_to be_deleted }
85
- end
86
- end
87
-
88
- describe '#duplicate_on_hold?' do
89
- context 'given fetching a reference returns an duplicate_on_hold status' do
90
- let(:data) { {"status"=>"duplicate_on_hold"} }
91
- it { expect(reference).to be_duplicate_on_hold }
92
- end
93
-
94
- context 'given fetching a reference does not return an duplicate_on_hold status' do
95
- let(:data) { {"status"=>"unknown"} }
96
- it { expect(reference).not_to be_duplicate_on_hold }
97
- end
98
- end
99
-
100
- describe '#inactive?' do
101
- context 'given fetching a reference returns an inactive status' do
102
- let(:data) { {"status"=>"inactive"} }
103
- it { expect(reference).to be_inactive }
104
- end
105
-
106
- context 'given fetching a reference does not return an inactive status' do
107
- let(:data) { {"status"=>"unknown"} }
108
- it { expect(reference).not_to be_inactive }
109
- end
110
- end
111
-
112
- describe '#live_streaming_processing?' do
113
- context 'given fetching a reference returns an live_streaming_processing status' do
114
- let(:data) { {"status"=>"live_streaming_processing"} }
115
- it { expect(reference).to be_live_streaming_processing }
116
- end
117
-
118
- context 'given fetching a reference does not return an live_streaming_processing status' do
119
- let(:data) { {"status"=>"unknown"} }
120
- it { expect(reference).not_to be_live_streaming_processing }
121
- end
122
- end
123
-
124
- describe '#urgent_reference_processing?' do
125
- context 'given fetching a reference returns an urgent_reference_processing status' do
126
- let(:data) { {"status"=>"urgent_reference_processing"} }
127
- it { expect(reference).to be_urgent_reference_processing }
128
- end
129
-
130
- context 'given fetching a reference does not return an urgent_reference_processing status' do
131
- let(:data) { {"status"=>"unknown"} }
132
- it { expect(reference).not_to be_urgent_reference_processing }
133
- end
134
- end
135
-
136
- describe '#status_reason' do
137
- context 'given fetching a reference returns a statusReason' do
138
- let(:data) { {"statusReason"=>"explanation"} }
139
- it { expect(reference.status_reason).to eq 'explanation' }
140
- end
141
- end
142
-
143
- describe '#duplicate_leader' do
144
- context 'given fetching a reference returns a duplicateLeader' do
145
- let(:data) { {"duplicateLeader"=>"123456"} }
146
- it { expect(reference.duplicate_leader).to eq '123456' }
147
- end
148
- end
149
-
150
- describe '#length' do
151
- context 'given fetching a reference returns a length' do
152
- let(:data) { {"length"=>354.66} }
153
- it { expect(reference.length).to eq 354.66 }
154
- end
155
- end
156
-
157
- describe '#video_id' do
158
- context 'given fetching a reference returns an videoId' do
159
- let(:data) { {"videoId"=>"9bZkp7q19f0"} }
160
- it { expect(reference.video_id).to eq '9bZkp7q19f0' }
161
- end
162
- end
163
-
164
- describe '#claim_id' do
165
- context 'given fetching a reference returns an claimId' do
166
- let(:data) { {"claimId"=>"aBcD1EfGHIk"} }
167
- it { expect(reference.claim_id).to eq 'aBcD1EfGHIk' }
168
- end
169
- end
170
-
171
- describe '#urgent?' do
172
- context 'given fetching a reference returns an urgent status true' do
173
- let(:data) { {"urgent"=>true} }
174
- it { expect(reference).to be_urgent }
175
- end
176
-
177
- context 'given fetching a reference returns an urgent status false' do
178
- let(:data) { {"urgent"=>false} }
179
- it { expect(reference).not_to be_urgent }
180
- end
181
- end
182
-
183
- describe '#content_type' do
184
- context 'given fetching a reference returns a content type' do
185
- let(:data) { {"contentType"=>"audio"} }
186
- it { expect(reference.content_type).to eq 'audio' }
187
- end
188
- end
189
-
190
- describe '#audio?' do
191
- context 'given fetching a reference returns an audio content type' do
192
- let(:data) { {"contentType"=>"audio"} }
193
- it { expect(reference).to be_audio }
194
- end
195
-
196
- context 'given fetching a reference does not return an audio content type' do
197
- let(:data) { {"contentType"=>"audiovisual"} }
198
- it { expect(reference).not_to be_audio }
199
- end
200
- end
201
-
202
- describe '#video?' do
203
- context 'given fetching a reference returns an video content type' do
204
- let(:data) { {"contentType"=>"video"} }
205
- it { expect(reference).to be_video }
206
- end
207
-
208
- context 'given fetching a reference does not return an video content type' do
209
- let(:data) { {"contentType"=>"audiovisual"} }
210
- it { expect(reference).not_to be_video }
211
- end
212
- end
213
-
214
- describe '#audiovisual?' do
215
- context 'given fetching a reference returns an audiovisual content type' do
216
- let(:data) { {"contentType"=>"audiovisual"} }
217
- it { expect(reference).to be_audiovisual }
218
- end
219
-
220
- context 'given fetching a reference does not return an audiovisual content type' do
221
- let(:data) { {"contentType"=>"audio"} }
222
- it { expect(reference).not_to be_audiovisual }
223
- end
224
- end
225
-
226
- describe '#audioswap_enabled?' do
227
- context 'given fetching a reference returns audioswapEnabled true' do
228
- let(:data) { {"audioswapEnabled"=>true} }
229
- it { expect(reference).to be_audioswap_enabled }
230
- end
231
-
232
- context 'given fetching a reference returns audioswapEnabled false' do
233
- let(:data) { {"audioswap_enabled"=>false} }
234
- it { expect(reference).not_to be_audioswap_enabled }
235
- end
236
- end
237
-
238
- describe '#ignore_fp_match?' do
239
- context 'given fetching a reference returns ignoreFpMatch true' do
240
- let(:data) { {"ignoreFpMatch"=>true} }
241
- it { expect(reference.ignore_fp_match?).to be true }
242
- end
243
-
244
- context 'given fetching a reference returns ignoreFpMatch false' do
245
- let(:data) { {"ignoreFpMatch"=>false} }
246
- it { expect(reference.ignore_fp_match?).to be false }
247
- end
248
- end
249
- end
@@ -1,204 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/request'
3
-
4
-
5
- describe Yt::Request do
6
- subject(:request) { Yt::Request.new host: 'example.com' }
7
- let(:response) { response_class.new nil, nil, nil }
8
- let(:response_body) { }
9
-
10
- describe '#run' do
11
- context 'given a request that returns' do
12
- before { allow(response).to receive(:body).and_return response_body }
13
- before { expect(Net::HTTP).to receive(:start).once.and_return response }
14
-
15
- context 'a success code 2XX' do
16
- let(:response_class) { Net::HTTPOK }
17
-
18
- it { expect{request.run}.not_to fail }
19
- end
20
-
21
- context 'an error code 5XX' do
22
- let(:response_class) { Net::HTTPServerError }
23
- let(:retry_response) { retry_response_class.new nil, nil, nil }
24
- before { allow(retry_response).to receive(:body) }
25
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
26
-
27
- context 'every time' do
28
- let(:retry_response_class) { Net::HTTPServerError }
29
-
30
- it { expect{request.run}.to fail }
31
- end
32
-
33
- context 'but returns a success code 2XX the second time' do
34
- let(:retry_response_class) { Net::HTTPOK }
35
-
36
- it { expect{request.run}.not_to fail }
37
- end
38
- end
39
-
40
- context 'an error code 403 with a "quota exceeded message"' do
41
- let(:response_class) { Net::HTTPForbidden }
42
- let(:retry_response) { retry_response_class.new nil, nil, nil }
43
- let(:response_body) { "{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"youtube.quota\",\n \"reason\": \"quotaExceeded\",\n \"message\": \"The request cannot be completed because you have exceeded your \\u003ca href=\\\"/youtube/v3/getting-started#quota\\\"\\u003equota\\u003c/a\\u003e.\"\n }\n ],\n \"code\": 403,\n \"message\": \"The request cannot be completed because you have exceeded your \\u003ca href=\\\"/youtube/v3/getting-started#quota\\\"\\u003equota\\u003c/a\\u003e.\"\n }\n}\n" }
44
- before { allow(retry_response).to receive(:body) }
45
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
46
-
47
- context 'every time' do
48
- let(:retry_response_class) { Net::HTTPForbidden }
49
-
50
- it { expect{request.run}.to fail }
51
- end
52
-
53
- context 'but returns a success code 2XX the second time' do
54
- let(:retry_response_class) { Net::HTTPOK }
55
-
56
- it { expect{request.run}.not_to fail }
57
- end
58
- end
59
-
60
- context 'an error code 401' do
61
- let(:response_class) { Net::HTTPUnauthorized }
62
-
63
- it { expect{request.run}.to fail }
64
- end
65
-
66
- context 'any other non-2XX error code' do
67
- let(:response_class) { Net::HTTPNotFound }
68
-
69
- it { expect{request.run}.to fail }
70
- end
71
- end
72
-
73
- # TODO: clean up the following tests, removing repetitions
74
- context 'given a request that raises' do
75
- before { expect(Net::HTTP).to receive(:start).once.and_raise http_error }
76
-
77
- # NOTE: This test is just a reflection of YouTube irrational behavior of
78
- # being unavailable once in a while, and therefore causing Net::HTTP to
79
- # fail, although retrying after some seconds works.
80
- context 'an OpenSSL::SSL::SSLError' do
81
- let(:http_error) { OpenSSL::SSL::SSLError.new }
82
-
83
- context 'every time' do
84
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
85
-
86
- it { expect{request.run}.to fail }
87
- end
88
-
89
- context 'but works the second time' do
90
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
91
- before { allow(retry_response).to receive(:body) }
92
- let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
93
-
94
- it { expect{request.run}.not_to fail }
95
- end
96
- end
97
-
98
- # NOTE: This test is just a reflection of YouTube irrational behavior of
99
- # being unavailable once in a while, and therefore causing Net::HTTP to
100
- # fail, although retrying after some seconds works.
101
- context 'an Errno::ETIMEDOUT' do
102
- let(:http_error) { Errno::ETIMEDOUT.new }
103
-
104
- context 'every time' do
105
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
106
-
107
- it { expect{request.run}.to fail }
108
- end
109
-
110
- context 'but works the second time' do
111
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
112
- before { allow(retry_response).to receive(:body) }
113
- let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
114
-
115
- it { expect{request.run}.not_to fail }
116
- end
117
- end
118
-
119
- # NOTE: This test is just a reflection of YouTube irrational behavior of
120
- # being unavailable once in a while, and therefore causing Net::HTTP to
121
- # fail, although retrying after some seconds works.
122
- context 'an Errno::ENETUNREACH' do
123
- let(:http_error) { Errno::ENETUNREACH.new }
124
-
125
- context 'every time' do
126
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
127
-
128
- it { expect{request.run}.to fail }
129
- end
130
-
131
- context 'but works the second time' do
132
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
133
- before { allow(retry_response).to receive(:body) }
134
- let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
135
-
136
- it { expect{request.run}.not_to fail }
137
- end
138
- end
139
-
140
- # NOTE: This test is just a reflection of YouTube irrational behavior of
141
- # being unavailable once in a while, and therefore causing Net::HTTP to
142
- # fail, although retrying after some seconds works.
143
- context 'an Errno::EHOSTUNREACH' do
144
- let(:http_error) { Errno::EHOSTUNREACH.new }
145
-
146
- context 'every time' do
147
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
148
-
149
- it { expect{request.run}.to fail }
150
- end
151
-
152
- context 'but works the second time' do
153
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
154
- before { allow(retry_response).to receive(:body) }
155
- let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
156
-
157
- it { expect{request.run}.not_to fail }
158
- end
159
- end
160
-
161
- # NOTE: This test is just a reflection of YouTube irrational behavior of
162
- # being unavailable once in a while, and therefore causing Net::HTTP to
163
- # fail, although retrying after some seconds works.
164
- context 'an OpenSSL::SSL::SSLErrorWaitReadable', ruby21: true do
165
- let(:http_error) { OpenSSL::SSL::SSLErrorWaitReadable.new }
166
-
167
- context 'every time' do
168
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
169
-
170
- it { expect{request.run}.to fail }
171
- end
172
-
173
- context 'but works the second time' do
174
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
175
- before { allow(retry_response).to receive(:body) }
176
- let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
177
-
178
- it { expect{request.run}.not_to fail }
179
- end
180
- end
181
-
182
- # NOTE: This test is just a reflection of YouTube irrational behavior of
183
- # being unavailable once in a while, and therefore causing Net::HTTP to
184
- # fail, although retrying after some seconds works.
185
- context 'a SocketError', ruby21: true do
186
- let(:http_error) { SocketError.new }
187
-
188
- context 'every time' do
189
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
190
-
191
- it { expect{request.run}.to fail }
192
- end
193
-
194
- context 'but works the second time' do
195
- before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
196
- before { allow(retry_response).to receive(:body) }
197
- let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
198
-
199
- it { expect{request.run}.not_to fail }
200
- end
201
- end
202
- end
203
- end
204
- end