Skip to content
Newer
Older
100644 128 lines (101 sloc) 3.66 KB
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 23, 2010
1 require "spec_helper"
2
3 describe Whois::Client do
4
94d9e7b @weppos context/describe
authored Feb 17, 2011
5 describe "#initialize" do
961bfc3 @weppos Store the hash of settings passed to the Client.
authored Dec 20, 2010
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 Sep 22, 2010
12 end
13
961bfc3 @weppos Store the hash of settings passed to the Client.
authored Dec 20, 2010
14
15 it "accepts a timeout setting with a value in seconds" do
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
16 client = klass.new(:timeout => 100)
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
17 client.timeout.should == 100
18 end
19
961bfc3 @weppos Store the hash of settings passed to the Client.
authored Dec 20, 2010
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 Dec 20, 2010
21 client = klass.new(:timeout => nil)
22 client.timeout.should be_nil
23 end
24
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
25 it "accepts a block" do
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
26 klass.new do |client|
27 client.should be_instance_of(klass)
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
28 end
29 end
961bfc3 @weppos Store the hash of settings passed to the Client.
authored Dec 20, 2010
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 Sep 22, 2010
41 end
42
94d9e7b @weppos context/describe
authored Feb 17, 2011
43 describe "#query" do
961bfc3 @weppos Store the hash of settings passed to the Client.
authored Dec 20, 2010
44 it "coerces the argument to string" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored Dec 20, 2010
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 Sep 22, 2010
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 Dec 20, 2010
49
50 server = Whois::Server::Adapters::Base.new(:tld, ".test", "example.test")
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
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 Dec 20, 2010
53 klass.new.query(["google", ".", "test"])
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
54 end
55
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
56 it "detects email" do
57 lambda do
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
58 klass.new.query("weppos@weppos.net")
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
59 end.should raise_error(Whois::ServerNotSupported)
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
60 end
61
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
62 it "works with domain with no whois" do
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
63 Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None)
64
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
65 lambda do
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
66 klass.new.query("domain.nowhois")
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
67 end.should raise_error(Whois::NoInterfaceError, /no whois server/)
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
68 end
69
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
70 it "works with domain with web whois" do
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
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 Nov 21, 2010
73 lambda do
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
74 klass.new.query("domain.webwhois")
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
75 end.should raise_error(Whois::WebInterfaceError, /www\.nic\.test/)
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
76 end
77
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
78 it "raises if timeout is exceeded" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored Dec 20, 2010
79 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
80 def query(*args)
81 sleep(2)
82 end
83 end
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored Dec 20, 2010
84 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "example.test"))
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
85
86 client = klass.new(:timeout => 1)
87 lambda { client.query("foo.com") }.should raise_error(Timeout::Error)
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
88 end
89
94d9e7b @weppos context/describe
authored Feb 17, 2011
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 Dec 20, 2010
91 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
92 def query(*args)
93 sleep(1)
94 end
95 end
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored Dec 20, 2010
96 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "example.test"))
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
97
98 client = klass.new(:timeout => 5)
99 lambda { client.query("foo.com") }.should_not raise_error
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
100 end
101
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
102 it "supports unlimited timeout" do
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored Dec 20, 2010
103 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
104 def query(*args)
105 sleep(1)
106 end
107 end
e6e7167 @weppos The client can provide additional settings to the underlying WHOIS ad…
authored Dec 20, 2010
108 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "example.test"))
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
109
110 client = klass.new.tap { |c| c.timeout = nil }
111 lambda { client.query("foo.com") }.should_not raise_error
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
112 end
113
114 end
115
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
116 # FIXME: use RSpec metadata
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
117 need_connectivity do
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
118 describe "#query" do
119 it "sends a query for given domain" do
5b012c3 @weppos klass returns the currently described class.
authored Nov 26, 2010
120 answer = klass.new.query("weppos.it")
45806c5 @weppos Convert Test::Unit to RSpec.
authored Nov 21, 2010
121 assert answer.match?(/Domain:\s+weppos\.it/)
122 assert answer.match?(/Created:/)
123 end
082fcd4 @weppos client_test.rb => client_spec.rb
authored Sep 22, 2010
124 end
125 end
126
127 end
Something went wrong with that request. Please try again.