|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe IndieWeb::Endpoints::Client, '#response' do |
4 | | - let(:url) { 'https://example.com' } |
5 | | - |
6 | | - let(:client) { described_class.new(url) } |
7 | | - let(:request) { stub_request(:get, url) } |
8 | | - |
9 | | - context 'when rescuing an HTTP::ConnectionError' do |
10 | | - before do |
11 | | - request.to_raise(HTTP::ConnectionError) |
12 | | - end |
13 | | - |
14 | | - it 'raises an HttpError' do |
15 | | - expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError) |
16 | | - end |
17 | | - end |
18 | | - |
19 | | - context 'when rescuing an HTTP::TimeoutError' do |
20 | | - before do |
21 | | - request.to_raise(HTTP::TimeoutError) |
22 | | - end |
23 | | - |
24 | | - it 'raises an HttpError' do |
25 | | - expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError) |
26 | | - end |
27 | | - end |
28 | | - |
29 | | - context 'when rescuing an HTTP::Redirector::TooManyRedirectsError' do |
30 | | - before do |
31 | | - request.to_raise(HTTP::Redirector::TooManyRedirectsError) |
32 | | - end |
| 4 | + subject(:response) { described_class.new(url).response } |
33 | 5 |
|
34 | | - it 'raises an HttpError' do |
35 | | - expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError) |
36 | | - end |
37 | | - end |
38 | | - |
39 | | - context 'when given an invalid URL' do |
40 | | - let(:url) { 'http:' } |
41 | | - |
42 | | - it 'raises an InvalidURIError' do |
43 | | - expect { client.response }.to raise_error(IndieWeb::Endpoints::InvalidURIError) |
44 | | - end |
45 | | - end |
46 | | - |
47 | | - context 'when given a relative URL' do |
48 | | - let(:url) { '../foo/bar/biz/baz' } |
49 | | - |
50 | | - it 'raises an HttpError' do |
51 | | - message = 'unknown scheme: ' |
52 | | - |
53 | | - expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError, message) |
54 | | - end |
55 | | - end |
56 | | - |
57 | | - context 'when given a URL with an invalid protocol' do |
58 | | - let(:url) { 'file:///foo/bar/baz' } |
| 6 | + let(:url) { 'https://example.com' } |
59 | 7 |
|
60 | | - it 'raises an HttpError' do |
61 | | - message = 'unknown scheme: file' |
| 8 | + context 'when rescuing from an HTTP::Error' do |
| 9 | + it 'raises an IndieWeb::Endpoints::HttpError' do |
| 10 | + stub_request(:get, url).to_raise(HTTP::Error) |
62 | 11 |
|
63 | | - expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError, message) |
| 12 | + expect { response }.to raise_error(IndieWeb::Endpoints::HttpError) |
64 | 13 | end |
65 | 14 | end |
66 | 15 | end |
0 commit comments