Skip to content

Commit 5b92119

Browse files
committed
🚜 Refactor Tractor those specs 🚜
1 parent c87ba28 commit 5b92119

12 files changed

Lines changed: 413 additions & 1505 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe IndieWeb::Endpoints::Client, '#endpoints' do
4+
# TODO: Rework these specs to use WebMock: https://github.com/bblimke/webmock
5+
context 'when running the webmention.rocks Endpoint Discovery tests' do
6+
WebmentionRocks::ENDPOINT_DISCOVERY_TESTS.each do |url, regexp|
7+
describe url do
8+
subject { described_class.new(url).endpoints[:webmention] }
9+
10+
it { is_expected.to match(regexp) }
11+
end
12+
end
13+
end
14+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe IndieWeb::Endpoints::Client, '#inspect' do
4+
subject { described_class.new('https://example.com').inspect }
5+
6+
it { is_expected.to match(/^#<#{described_class}:0x[a-f0-9]+ uri: ".*">$/) }
7+
end
Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,15 @@
11
# frozen_string_literal: true
22

33
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 }
335

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' }
597

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)
6211

63-
expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError, message)
12+
expect { response }.to raise_error(IndieWeb::Endpoints::HttpError)
6413
end
6514
end
6615
end
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# frozen_string_literal: true
22

33
RSpec.describe IndieWeb::Endpoints::Client do
4-
context 'when not given a String-like object' do
5-
it 'raises a NoMethodError' do
6-
expect { described_class.new(nil) }.to raise_error(NoMethodError)
4+
subject(:client) { described_class.new(url) }
5+
6+
context 'when given invalid arguments' do
7+
let(:url) { '1:' }
8+
9+
it 'raises an IndieWeb::Endpoints::InvalidURIError' do
10+
expect { client }.to raise_error(IndieWeb::Endpoints::InvalidURIError)
711
end
812
end
913
end

spec/lib/indieweb/endpoints/parsers/authorization_endpoint_parser_spec.rb

Lines changed: 0 additions & 281 deletions
This file was deleted.

0 commit comments

Comments
 (0)