|
50 | 50 | expect(unparseable_response.http_version).to eq(@response_object.http_version)
|
51 | 51 | end
|
52 | 52 |
|
53 |
| - context 'when raise_on is supplied' do |
| 53 | + context 'test raise_on requests' do |
54 | 54 | let(:request) { HTTParty::Request.new(Net::HTTP::Get, '/', raise_on: [404]) }
|
| 55 | + let(:body) { 'Not Found' } |
| 56 | + let(:response) { Net::HTTPNotFound.new('1.1', 404, body) } |
55 | 57 |
|
56 |
| - context "and response's status code is in range" do |
57 |
| - let(:body) { 'Not Found' } |
58 |
| - let(:response) { Net::HTTPNotFound.new('1.1', 404, body) } |
| 58 | + subject { described_class.new(request, response, @parsed_response) } |
59 | 59 |
|
60 |
| - before do |
61 |
| - allow(response).to receive(:body).and_return(body) |
| 60 | + before do |
| 61 | + allow(response).to receive(:body).and_return(body) |
| 62 | + end |
| 63 | + |
| 64 | + context 'when raise_on is a number' do |
| 65 | + let(:raise_on) { [404] } |
| 66 | + |
| 67 | + context "and response's status code is in range" do |
| 68 | + it 'throws exception' do |
| 69 | + expect{ subject }.to raise_error(HTTParty::ResponseError, "Code 404 - #{body}") |
| 70 | + end |
62 | 71 | end
|
63 | 72 |
|
64 |
| - subject { described_class.new(request, response, @parsed_response) } |
| 73 | + context "and response's status code is not in range" do |
| 74 | + subject { described_class.new(request, @response_object, @parsed_response) } |
65 | 75 |
|
66 |
| - it 'throws exception' do |
67 |
| - expect{ subject }.to raise_error(HTTParty::ResponseError, "Code 404 - #{body}") |
| 76 | + it 'does not throw exception' do |
| 77 | + expect{ subject }.not_to raise_error |
| 78 | + end |
68 | 79 | end
|
69 | 80 | end
|
70 | 81 |
|
71 |
| - context "and response's status code is not in range" do |
72 |
| - subject { described_class.new(request, @response_object, @parsed_response) } |
| 82 | + context 'when raise_on is a regexpr' do |
| 83 | + let(:raise_on) { ['4[0-9]*'] } |
| 84 | + |
| 85 | + context "and response's status code is in range" do |
| 86 | + it 'throws exception' do |
| 87 | + expect{ subject }.to raise_error(HTTParty::ResponseError, "Code 404 - #{body}") |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + context "and response's status code is not in range" do |
| 92 | + subject { described_class.new(request, @response_object, @parsed_response) } |
73 | 93 |
|
74 |
| - it 'does not throw exception' do |
75 |
| - expect{ subject }.not_to raise_error |
| 94 | + it 'does not throw exception' do |
| 95 | + expect{ subject }.not_to raise_error |
| 96 | + end |
76 | 97 | end
|
77 | 98 | end
|
78 | 99 | end
|
|
0 commit comments