Skip to content

Commit 25f50e8

Browse files
committed
fix: yard docs & add missing
1 parent 535ad80 commit 25f50e8

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

spec/helper_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,32 @@
2525
it 'returns the full host' do
2626
expect(described_class.url_to_host_name('https://news.bbc.co.uk/world')).to eq('news.bbc.co.uk')
2727
end
28+
29+
it 'returns nil for blank or invalid URLs', :aggregate_failures do
30+
expect(described_class.url_to_host_name(nil)).to be_nil
31+
expect(described_class.url_to_host_name('')).to be_nil
32+
expect(described_class.url_to_host_name('not a url')).to be_nil
33+
end
34+
end
35+
36+
describe 'legacy naming guardrail' do
37+
it 'does not expose url_to_directory_name' do
38+
expect(described_class).not_to respond_to(:url_to_directory_name)
39+
end
40+
end
41+
42+
describe '.registrable_domain' do
43+
it 'falls back to host when PublicSuffix returns nil' do
44+
allow(PublicSuffix).to receive(:domain).with('example.local').and_return(nil)
45+
46+
expect(described_class.send(:registrable_domain, 'example.local')).to eq('example.local')
47+
end
48+
49+
it 'falls back to host when PublicSuffix raises DomainInvalid' do
50+
allow(PublicSuffix).to receive(:domain).with('invalid..host')
51+
.and_raise(PublicSuffix::DomainInvalid)
52+
53+
expect(described_class.send(:registrable_domain, 'invalid..host')).to eq('invalid..host')
54+
end
2855
end
2956
end

spec/support/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
module Helper
1111
##
1212
# @param url [String]
13-
# @return [String]
13+
# @return [String, nil]
1414
def self.url_to_registrable_domain(url)
1515
host = url_to_host_name(url)
1616
return host unless host

0 commit comments

Comments
 (0)