domainator 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe Domainator do
5
+ describe '#parse' do
6
+ shared_examples_for 'a valid URL' do |domain|
7
+ it 'returns the domain when given a string' do
8
+ expect(subject.parse(url)).to eq domain
9
+ end
10
+
11
+ it 'returns the domain when given a URI' do
12
+ uri = URI.parse(url)
13
+ expect(subject.parse(uri)).to eq domain
14
+ end
15
+ end
16
+
17
+ describe 'for a valid LTR URI' do
18
+ let(:url) { 'http://www.example.com/foo?x=y&y=z' }
19
+ it_behaves_like 'a valid URL', 'example.com'
20
+ end
21
+
22
+ describe 'for a valid RTL URI', skip: 'RTL extensions not working' do
23
+ let(:url) { 'http://مليسيا.مليسيا.مليسيا' }
24
+ it_behaves_like 'a valid URL', 'مليسيا.مليسيا'
25
+ end
26
+
27
+ describe 'for an invalid URI' do
28
+ it 'raises an error' do
29
+ url = 42
30
+ expect { subject.parse(url) }.to raise_error ArgumentError
31
+ end
32
+ end
33
+
34
+ describe 'for an unparseable URI' do
35
+ it 'raises an error' do
36
+ url = ':'
37
+ expect { subject.parse(url) }.to raise_error URI::InvalidURIError
38
+ end
39
+ end
40
+
41
+ describe 'for an nonexistent domain' do
42
+ it 'raises an error' do
43
+ url = 'http://www.example.foo'
44
+ expect { subject.parse(url) }.to raise_error Domainator::NotFoundError
45
+ end
46
+ end
47
+
48
+ describe 'when given a custom list of extensions' do
49
+ subject { described_class.new(extensions) }
50
+
51
+ let(:extensions) { %w[.uk .co.uk].to_set }
52
+
53
+ it 'returns the domain for a valid URI' do
54
+ expect(subject.parse('http://www.example.co.uk')).to eq 'example.co.uk'
55
+ end
56
+
57
+ it 'raises an error for an invalid URI' do
58
+ expect { subject.parse('http://www.example.com') }.to raise_error Domainator::NotFoundError
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '.parse' do
64
+ subject { described_class }
65
+
66
+ let(:url) { 'http://www.google.com' }
67
+
68
+ it 'delegates to a new instance' do
69
+ instance = subject.new
70
+ allow(subject).to receive(:new).and_return(instance)
71
+ expect(instance).to receive(:parse).with(url)
72
+ subject.parse(url)
73
+ end
74
+
75
+ it 'includes the provided extension list' do
76
+ extensions = %w[.uk .co.uk].to_set
77
+ instance = subject.new(extensions)
78
+ allow(subject).to receive(:new).with(extensions).and_return(instance)
79
+ expect(instance).to receive(:parse).with(url)
80
+ subject.parse(url, extensions)
81
+ end
82
+ end
83
+
84
+ describe '.default_extensions' do
85
+ subject { described_class }
86
+
87
+ it 'returns a set' do
88
+ expect(subject.default_extensions).to be_a Set
89
+ end
90
+
91
+ it 'prefixes each extension with a dot' do
92
+ expect(subject.default_extensions).to all start_with('.')
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,17 @@
1
+ require 'domainator'
2
+
3
+ # Requires supporting ruby files with custom matchers and macros, etc,
4
+ # in spec/support/ and its subdirectories.
5
+ Dir[File.expand_path('spec/support/**/*.rb')].each(&method(:require))
6
+
7
+ RSpec.configure do |config|
8
+ # Run specs in random order to surface order dependencies. If you find an
9
+ # order dependency and want to debug it, you can fix the order by providing
10
+ # the seed, which is printed after each run.
11
+ # --seed 1234
12
+ config.order = 'random'
13
+
14
+ # Enable filtered runs.
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run focus: true
17
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domainator
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Huggins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Parse the registered domain name from a URL.
56
+ email:
57
+ - matt.huggins@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - domainator.gemspec
69
+ - lib/domainator.rb
70
+ - lib/domainator/version.rb
71
+ - lib/extensions.txt
72
+ - spec/domainator_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: https://github.com/mhuggins/domainator
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Parse the registered domain name from a URL.
98
+ test_files:
99
+ - spec/domainator_spec.rb
100
+ - spec/spec_helper.rb