Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'retry-youtube-request-when-they-might-work-the-second-t…
…ime'
- Loading branch information
Showing
9 changed files
with
109 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
yt (0.5.12) | ||
yt (0.5.13) | ||
activesupport | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Yt | ||
VERSION = '0.5.12' | ||
VERSION = '0.5.13' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,74 @@ | ||
require 'spec_helper' | ||
require 'yt/models/request' | ||
|
||
|
||
describe Yt::Request do | ||
subject(:request) { Yt::Request.new attrs } | ||
let(:attrs) { {host: 'example.com'} } | ||
before { expect(Net::HTTP).to receive(:start).and_return response } | ||
before { allow(response).to receive(:body) } | ||
subject(:request) { Yt::Request.new host: 'example.com' } | ||
let(:response) { response_class.new nil, nil, nil } | ||
let(:response_body) { } | ||
before { allow(response).to receive(:body).and_return response_body } | ||
before { expect(Net::HTTP).to receive(:start).once.and_return response } | ||
|
||
describe '#run' do | ||
context 'given a request that returns a 500 code' do | ||
let(:response) { Net::HTTPServerError.new nil, nil, nil } | ||
it { expect{request.run}.to fail } | ||
end | ||
context 'given a request that returns' do | ||
context 'a success code 2XX' do | ||
let(:response_class) { Net::HTTPOK } | ||
|
||
context 'given a request that returns a 401 code' do | ||
let(:response) { Net::HTTPUnauthorized.new nil, nil, nil } | ||
it { expect{request.run}.to fail } | ||
end | ||
it { expect{request.run}.not_to fail } | ||
end | ||
|
||
context 'given a request that returns a non-2XX code' do | ||
let(:response) { Net::HTTPNotFound.new nil, nil, nil } | ||
it { expect{request.run}.to fail } | ||
end | ||
context 'an error code 5XX' do | ||
let(:response_class) { Net::HTTPServerError } | ||
let(:retry_response) { retry_response_class.new nil, nil, nil } | ||
before { allow(retry_response).to receive(:body) } | ||
before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response } | ||
|
||
context 'every time' do | ||
let(:retry_response_class) { Net::HTTPServerError } | ||
|
||
it { expect{request.run}.to fail } | ||
end | ||
|
||
context 'but returns a success code 2XX the second time' do | ||
let(:retry_response_class) { Net::HTTPOK } | ||
|
||
it { expect{request.run}.not_to fail } | ||
end | ||
end | ||
|
||
context 'an error code 400 with "Invalid Query" message' do | ||
let(:response_class) { Net::HTTPBadRequest } | ||
let(:response_body) { {error: {errors: [message: message]}}.to_json } | ||
let(:message) { 'Invalid query. Query did not conform to the expectations' } | ||
|
||
let(:retry_response) { retry_response_class.new nil, nil, nil } | ||
before { allow(retry_response).to receive(:body) } | ||
before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response } | ||
|
||
context 'every time' do | ||
let(:retry_response_class) { Net::HTTPBadRequest } | ||
|
||
it { expect{request.run}.to fail } | ||
end | ||
|
||
context 'but returns a success code 2XX the second time' do | ||
let(:retry_response_class) { Net::HTTPOK } | ||
|
||
it { expect{request.run}.not_to fail } | ||
end | ||
end | ||
|
||
context 'an error code 401' do | ||
let(:response_class) { Net::HTTPUnauthorized } | ||
|
||
it { expect{request.run}.to fail } | ||
end | ||
|
||
context 'any other non-2XX error code' do | ||
let(:response_class) { Net::HTTPNotFound } | ||
|
||
context 'given a request that returns a 2XX code' do | ||
let(:response) { Net::HTTPOK.new nil, nil, nil } | ||
it { expect{request.run}.not_to fail } | ||
it { expect{request.run}.to fail } | ||
end | ||
end | ||
end | ||
end |