Skip to content

Commit

Permalink
🚜 Refactor Tractor those specs 🚜
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber623 committed Mar 9, 2022
1 parent c87ba28 commit 5b92119
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 1,505 deletions.
14 changes: 14 additions & 0 deletions spec/lib/indieweb/endpoints/client_endpoints_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

RSpec.describe IndieWeb::Endpoints::Client, '#endpoints' do
# TODO: Rework these specs to use WebMock: https://github.com/bblimke/webmock
context 'when running the webmention.rocks Endpoint Discovery tests' do
WebmentionRocks::ENDPOINT_DISCOVERY_TESTS.each do |url, regexp|
describe url do
subject { described_class.new(url).endpoints[:webmention] }

it { is_expected.to match(regexp) }
end
end
end
end
7 changes: 7 additions & 0 deletions spec/lib/indieweb/endpoints/client_inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

RSpec.describe IndieWeb::Endpoints::Client, '#inspect' do
subject { described_class.new('https://example.com').inspect }

it { is_expected.to match(/^#<#{described_class}:0x[a-f0-9]+ uri: ".*">$/) }
end
63 changes: 6 additions & 57 deletions spec/lib/indieweb/endpoints/client_response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,15 @@
# frozen_string_literal: true

RSpec.describe IndieWeb::Endpoints::Client, '#response' do
let(:url) { 'https://example.com' }

let(:client) { described_class.new(url) }
let(:request) { stub_request(:get, url) }

context 'when rescuing an HTTP::ConnectionError' do
before do
request.to_raise(HTTP::ConnectionError)
end

it 'raises an HttpError' do
expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError)
end
end

context 'when rescuing an HTTP::TimeoutError' do
before do
request.to_raise(HTTP::TimeoutError)
end

it 'raises an HttpError' do
expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError)
end
end

context 'when rescuing an HTTP::Redirector::TooManyRedirectsError' do
before do
request.to_raise(HTTP::Redirector::TooManyRedirectsError)
end
subject(:response) { described_class.new(url).response }

it 'raises an HttpError' do
expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError)
end
end

context 'when given an invalid URL' do
let(:url) { 'http:' }

it 'raises an InvalidURIError' do
expect { client.response }.to raise_error(IndieWeb::Endpoints::InvalidURIError)
end
end

context 'when given a relative URL' do
let(:url) { '../foo/bar/biz/baz' }

it 'raises an HttpError' do
message = 'unknown scheme: '

expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError, message)
end
end

context 'when given a URL with an invalid protocol' do
let(:url) { 'file:///foo/bar/baz' }
let(:url) { 'https://example.com' }

it 'raises an HttpError' do
message = 'unknown scheme: file'
context 'when rescuing from an HTTP::Error' do
it 'raises an IndieWeb::Endpoints::HttpError' do
stub_request(:get, url).to_raise(HTTP::Error)

expect { client.response }.to raise_error(IndieWeb::Endpoints::HttpError, message)
expect { response }.to raise_error(IndieWeb::Endpoints::HttpError)
end
end
end
10 changes: 7 additions & 3 deletions spec/lib/indieweb/endpoints/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# frozen_string_literal: true

RSpec.describe IndieWeb::Endpoints::Client do
context 'when not given a String-like object' do
it 'raises a NoMethodError' do
expect { described_class.new(nil) }.to raise_error(NoMethodError)
subject(:client) { described_class.new(url) }

context 'when given invalid arguments' do
let(:url) { '1:' }

it 'raises an IndieWeb::Endpoints::InvalidURIError' do
expect { client }.to raise_error(IndieWeb::Endpoints::InvalidURIError)
end
end
end

This file was deleted.

Loading

0 comments on commit 5b92119

Please sign in to comment.