Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 128 lines (101 sloc) 3.753 kb
082fcd4 @weppos client_test.rb => client_spec.rb
authored
1 require "spec_helper"
2
3 describe Whois::Client do
4
94d9e7b @weppos context/describe
authored
5 describe "#initialize" do
961bfc3 @weppos Store the hash of settings passed to the Client.
authored
6 it "accepts a zero parameters" do
7 lambda { klass.new }.should_not raise_error
8 end
9
10 it "accepts a settings parameter" do
11 lambda { klass.new({ :foo => "bar" }) }.should_not raise_error
082fcd4 @weppos client_test.rb => client_spec.rb
authored
12 end
13
961bfc3 @weppos Store the hash of settings passed to the Client.
authored
14
15 it "accepts a timeout setting with a value in seconds" do
5b012c3 @weppos klass returns the currently described class.
authored
16 client = klass.new(:timeout => 100)
082fcd4 @weppos client_test.rb => client_spec.rb
authored
17 client.timeout.should == 100
18 end
19
961bfc3 @weppos Store the hash of settings passed to the Client.
authored
20 it "accepts a timeout setting with a nil value" do
17ecc41 @weppos Fixed a bug which prevents a client to be created with nil timeout.
authored
21 client = klass.new(:timeout => nil)
22 client.timeout.should be_nil
23 end
24
45806c5 @weppos Convert Test::Unit to RSpec.
authored
25 it "accepts a block" do
5b012c3 @weppos klass returns the currently described class.
authored
26 klass.new do |client|
27 client.should be_instance_of(klass)
082fcd4 @weppos client_test.rb => client_spec.rb
authored
28 end
29 end
961bfc3 @weppos Store the hash of settings passed to the Client.
authored
30
31
32 it "defaults timeout setting to DEFAULT_TIMEOUT" do
33 client = klass.new
34 client.timeout.should == klass::DEFAULT_TIMEOUT
35 end
36
37 it "sets settings to given argument, except timeout" do
38 client = klass.new(:timeout => nil, :foo => "bar")
39 client.settings.should == { :foo => "bar" }
40 end
082fcd4 @weppos client_test.rb => client_spec.rb
authored
41 end
42
94d9e7b @weppos context/describe
authored
43 describe "#query" do
961bfc3 @weppos Store the hash of settings passed to the Client.
authored
44 it "coerces the argument to string" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored
45 # I can't use the String in place of instance_of(String)
46 # because Array#to_s behaves differently
082fcd4 @weppos client_test.rb => client_spec.rb
authored
47 # on Ruby 1.8.7 and Ruby 1.9.1
48 # http://redmine.ruby-lang.org/issues/show/2617
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored
49
50 server = Whois::Server::Adapters::Base.new(:tld, ".test", "example.test")
082fcd4 @weppos client_test.rb => client_spec.rb
authored
51 server.expects(:query).with(instance_of(String))
52 Whois::Server.expects(:guess).with(instance_of(String)).returns(server)
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored
53 klass.new.query(["google", ".", "test"])
082fcd4 @weppos client_test.rb => client_spec.rb
authored
54 end
55
45806c5 @weppos Convert Test::Unit to RSpec.
authored
56 it "detects email" do
57 lambda do
5b012c3 @weppos klass returns the currently described class.
authored
58 klass.new.query("weppos@weppos.net")
45806c5 @weppos Convert Test::Unit to RSpec.
authored
59 end.should raise_error(Whois::ServerNotSupported)
082fcd4 @weppos client_test.rb => client_spec.rb
authored
60 end
61
45806c5 @weppos Convert Test::Unit to RSpec.
authored
62 it "works with domain with no whois" do
082fcd4 @weppos client_test.rb => client_spec.rb
authored
63 Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None)
64
45806c5 @weppos Convert Test::Unit to RSpec.
authored
65 lambda do
5b012c3 @weppos klass returns the currently described class.
authored
66 klass.new.query("domain.nowhois")
45806c5 @weppos Convert Test::Unit to RSpec.
authored
67 end.should raise_error(Whois::NoInterfaceError, /no whois server/)
082fcd4 @weppos client_test.rb => client_spec.rb
authored
68 end
69
45806c5 @weppos Convert Test::Unit to RSpec.
authored
70 it "works with domain with web whois" do
082fcd4 @weppos client_test.rb => client_spec.rb
authored
71 Whois::Server.define(:tld, ".webwhois", nil, :adapter => Whois::Server::Adapters::Web, :web => "www.nic.test")
72
45806c5 @weppos Convert Test::Unit to RSpec.
authored
73 lambda do
5b012c3 @weppos klass returns the currently described class.
authored
74 klass.new.query("domain.webwhois")
45806c5 @weppos Convert Test::Unit to RSpec.
authored
75 end.should raise_error(Whois::WebInterfaceError, /www\.nic\.test/)
082fcd4 @weppos client_test.rb => client_spec.rb
authored
76 end
77
45806c5 @weppos Convert Test::Unit to RSpec.
authored
78 it "raises if timeout is exceeded" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored
79 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4 @weppos client_test.rb => client_spec.rb
authored
80 def query(*args)
81 sleep(2)
82 end
83 end
24a1ed7 @weppos Query object should match server
authored
84 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "whois.test"))
5b012c3 @weppos klass returns the currently described class.
authored
85
86 client = klass.new(:timeout => 1)
24a1ed7 @weppos Query object should match server
authored
87 lambda { client.query("example.test") }.should raise_error(Timeout::Error)
082fcd4 @weppos client_test.rb => client_spec.rb
authored
88 end
89
94d9e7b @weppos context/describe
authored
90 it "does not raise if timeout is not exceeded" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored
91 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4 @weppos client_test.rb => client_spec.rb
authored
92 def query(*args)
93 sleep(1)
94 end
95 end
24a1ed7 @weppos Query object should match server
authored
96 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "whois.test"))
5b012c3 @weppos klass returns the currently described class.
authored
97
98 client = klass.new(:timeout => 5)
24a1ed7 @weppos Query object should match server
authored
99 lambda { client.query("example.test") }.should_not raise_error
082fcd4 @weppos client_test.rb => client_spec.rb
authored
100 end
101
45806c5 @weppos Convert Test::Unit to RSpec.
authored
102 it "supports unlimited timeout" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored
103 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4 @weppos client_test.rb => client_spec.rb
authored
104 def query(*args)
105 sleep(1)
106 end
107 end
24a1ed7 @weppos Query object should match server
authored
108 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "whois.test"))
5b012c3 @weppos klass returns the currently described class.
authored
109
110 client = klass.new.tap { |c| c.timeout = nil }
24a1ed7 @weppos Query object should match server
authored
111 lambda { client.query("example.test") }.should_not raise_error
082fcd4 @weppos client_test.rb => client_spec.rb
authored
112 end
113
114 end
115
45806c5 @weppos Convert Test::Unit to RSpec.
authored
116 # FIXME: use RSpec metadata
082fcd4 @weppos client_test.rb => client_spec.rb
authored
117 need_connectivity do
45806c5 @weppos Convert Test::Unit to RSpec.
authored
118 describe "#query" do
119 it "sends a query for given domain" do
e94d872 @weppos Rename Whois::Answer to Whois::Record
authored
120 record = klass.new.query("weppos.it")
121 assert record.match?(/Domain:\s+weppos\.it/)
122 assert record.match?(/Created:/)
45806c5 @weppos Convert Test::Unit to RSpec.
authored
123 end
082fcd4 @weppos client_test.rb => client_spec.rb
authored
124 end
125 end
126
127 end
Something went wrong with that request. Please try again.