Skip to content
This repository
Newer
Older
100644 134 lines (107 sloc) 4.061 kb
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
1 require "spec_helper"
2
3 describe Whois::Client do
4
94d9e7be »
2011-02-17 context/describe
5 describe "#initialize" do
961bfc3a »
2010-12-20 Store the hash of settings passed to the Client.
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
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
12 end
13
961bfc3a »
2010-12-20 Store the hash of settings passed to the Client.
14
15 it "accepts a timeout setting with a value in seconds" do
5b012c31 »
2010-11-26 klass returns the currently described class.
16 client = klass.new(:timeout => 100)
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
17 client.timeout.should == 100
18 end
19
961bfc3a »
2010-12-20 Store the hash of settings passed to the Client.
20 it "accepts a timeout setting with a nil value" do
17ecc418 »
2010-12-20 Fixed a bug which prevents a client to be created with nil timeout.
21 client = klass.new(:timeout => nil)
22 client.timeout.should be_nil
23 end
24
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
25 it "accepts a block" do
5b012c31 »
2010-11-26 klass returns the currently described class.
26 klass.new do |client|
27 client.should be_instance_of(klass)
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
28 end
29 end
961bfc3a »
2010-12-20 Store the hash of settings passed to the Client.
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
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
41 end
42
94d9e7be »
2011-02-17 context/describe
43 describe "#query" do
e569a0c2 »
2012-03-05 Whois::Client#query is no longer case sensitive (closes GH-151).
44 it "converts the argument to string" do
e6e7167d »
2010-12-20 The client can provide additional settings to the underlying WHOIS ad…
45 # I can't use the String in place of instance_of(String)
46 # because Array#to_s behaves differently
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
47 # on Ruby 1.8.7 and Ruby 1.9.1
48 # http://redmine.ruby-lang.org/issues/show/2617
e6e7167d »
2010-12-20 The client can provide additional settings to the underlying WHOIS ad…
49
e569a0c2 »
2012-03-05 Whois::Client#query is no longer case sensitive (closes GH-151).
50 server = Whois::Server::Adapters::Base.new(:tld, ".test", "whois.test")
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
51 server.expects(:query).with(instance_of(String))
52 Whois::Server.expects(:guess).with(instance_of(String)).returns(server)
e569a0c2 »
2012-03-05 Whois::Client#query is no longer case sensitive (closes GH-151).
53 klass.new.query(["example", ".", "test"])
54 end
55
56 it "converts the argument to downcase" do
57 server = Whois::Server::Adapters::Base.new(:tld, ".test", "whois.test")
58 server.expects(:query).with("example.test")
55dcee15 »
2012-03-05 Fix invalid expectation, I want to check the case.
59 Whois::Server.expects(:guess).with("example.test").returns(server)
e569a0c2 »
2012-03-05 Whois::Client#query is no longer case sensitive (closes GH-151).
60 klass.new.query("Example.TEST")
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
61 end
62
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
63 it "detects email" do
64 lambda do
5b012c31 »
2010-11-26 klass returns the currently described class.
65 klass.new.query("weppos@weppos.net")
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
66 end.should raise_error(Whois::ServerNotSupported)
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
67 end
68
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
69 it "works with domain with no whois" do
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
70 Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None)
71
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
72 lambda do
5b012c31 »
2010-11-26 klass returns the currently described class.
73 klass.new.query("domain.nowhois")
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
74 end.should raise_error(Whois::NoInterfaceError, /no whois server/)
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
75 end
76
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
77 it "works with domain with web whois" do
7d18de1f »
2012-06-30 Deprecate options[:web] for :web adapter in favor of options[:url].
78 Whois::Server.define(:tld, ".webwhois", nil, :adapter => Whois::Server::Adapters::Web, :url => "http://www.example.com/")
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
79
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
80 lambda do
5b012c31 »
2010-11-26 klass returns the currently described class.
81 klass.new.query("domain.webwhois")
7d18de1f »
2012-06-30 Deprecate options[:web] for :web adapter in favor of options[:url].
82 end.should raise_error(Whois::WebInterfaceError, /www\.example\.com/)
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
83 end
84
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
85 it "raises if timeout is exceeded" do
e6e7167d »
2010-12-20 The client can provide additional settings to the underlying WHOIS ad…
86 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
87 def query(*args)
88 sleep(2)
89 end
90 end
24a1ed7f »
2012-03-05 Query object should match server
91 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "whois.test"))
5b012c31 »
2010-11-26 klass returns the currently described class.
92
93 client = klass.new(:timeout => 1)
24a1ed7f »
2012-03-05 Query object should match server
94 lambda { client.query("example.test") }.should raise_error(Timeout::Error)
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
95 end
96
94d9e7be »
2011-02-17 context/describe
97 it "does not raise if timeout is not exceeded" do
e6e7167d »
2010-12-20 The client can provide additional settings to the underlying WHOIS ad…
98 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
99 def query(*args)
100 sleep(1)
101 end
102 end
24a1ed7f »
2012-03-05 Query object should match server
103 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "whois.test"))
5b012c31 »
2010-11-26 klass returns the currently described class.
104
105 client = klass.new(:timeout => 5)
24a1ed7f »
2012-03-05 Query object should match server
106 lambda { client.query("example.test") }.should_not raise_error
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
107 end
108
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
109 it "supports unlimited timeout" do
e6e7167d »
2010-12-20 The client can provide additional settings to the underlying WHOIS ad…
110 adapter = Class.new(Whois::Server::Adapters::Base) do
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
111 def query(*args)
112 sleep(1)
113 end
114 end
24a1ed7f »
2012-03-05 Query object should match server
115 Whois::Server.expects(:guess).returns(adapter.new(:tld, ".test", "whois.test"))
5b012c31 »
2010-11-26 klass returns the currently described class.
116
117 client = klass.new.tap { |c| c.timeout = nil }
24a1ed7f »
2012-03-05 Query object should match server
118 lambda { client.query("example.test") }.should_not raise_error
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
119 end
120
121 end
122
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
123 # FIXME: use RSpec metadata
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
124 need_connectivity do
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
125 describe "#query" do
126 it "sends a query for given domain" do
e94d872d »
2011-03-15 Rename Whois::Answer to Whois::Record
127 record = klass.new.query("weppos.it")
128 assert record.match?(/Domain:\s+weppos\.it/)
129 assert record.match?(/Created:/)
45806c56 »
2010-11-21 Convert Test::Unit to RSpec.
130 end
082fcd4b »
2010-09-23 client_test.rb => client_spec.rb
131 end
132 end
133
134 end
Something went wrong with that request. Please try again.