/
whois_spec.rb
117 lines (96 loc) · 3.49 KB
/
whois_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# encoding: utf-8
require 'spec_helper'
describe Whoaz::Whois do
it { Whoaz.should respond_to :whois }
describe "empty domain query" do
it "should raise EmptyDomain" do
expect { Whoaz.whois }.to raise_error Whoaz::EmptyDomain, 'Domain not specified'
end
end
describe "invalid domain query" do
it "should raise InvalidDomain" do
expect { Whoaz.whois 'google' }.to raise_error Whoaz::InvalidDomain, 'Invalid domain specified'
expect { Whoaz.whois 'goo.gl' }.to raise_error Whoaz::InvalidDomain, 'Invalid domain specified'
expect { Whoaz.whois 'алм.az' }.to raise_error Whoaz::InvalidDomain, 'Domain contains non-ASCII characters'
end
end
describe "less than 3 characters long domain query" do
it "should raise DomainNameError" do
fake_url Whoaz::WHOIS_URL, 'less_than_3_chars', {:domain => 'i', :dom => '.az'}
expect { Whoaz.whois 'i.az' }.to raise_error Whoaz::DomainNameError, 'Whois query for this domain name is not supported.'
end
end
context "should check domain registration" do
context "when registered" do
before { fake_url Whoaz::WHOIS_URL, 'organization', {:domain => 'google', :dom => '.az'} }
describe "#free?" do
specify { Whoaz.whois('google.az').free?.should be_false }
end
describe "#registered?" do
specify { Whoaz.whois('google.az').registered?.should be_true }
end
end
context "when not registered" do
before { fake_url Whoaz::WHOIS_URL, 'free', {:domain => '404', :dom => '.az'} }
describe "#free?" do
specify { Whoaz.whois('google.az').free?.should be_true }
end
describe "#registered?" do
specify { Whoaz.whois('404.az').registered?.should be_false }
end
end
end
context "should return a whois info" do
context "when a person" do
before { fake_url Whoaz::WHOIS_URL, 'person', {:domain => 'johnsmith', :dom => '.az'} }
subject { Whoaz.whois 'johnsmith.az' }
describe "#organization" do
specify { subject.organization.should be_nil }
end
describe "#name" do
it "should return a registrant name" do
subject.name.should == 'John Smith'
end
end
end
context "when an organization" do
before { fake_url Whoaz::WHOIS_URL, 'organization', {:domain => 'google', :dom => '.az'} }
subject { Whoaz.whois 'google.az' }
describe "#organization" do
it "should return a registrant organization" do
subject.organization.should == 'Google Inc.'
end
end
describe "#name" do
it "should return a registrant name" do
subject.name.should == 'Admin'
end
end
describe "#address" do
it "should return a registrant address" do
subject.address.should == '94043, Mountain View, 1600 Amphitheatre Parkway'
end
end
describe "#phone" do
it "should return a registrant phone" do
subject.phone.should == '+16503300100'
end
end
describe "#fax" do
it "should return a registrant fax" do
subject.fax.should == '+16506188571'
end
end
describe "#email" do
it "should return a registrant email" do
subject.email.should == 'dns-admin@google.com'
end
end
describe "#nameservers" do
it "should return domain nameservers" do
subject.nameservers.should == ["ns1.google.com", "ns2.google.com"]
end
end
end
end
end