Skip to content
Browse files

klass returns the currently described class.

  • Loading branch information...
1 parent d52c2b8 commit 5b012c31093ce92eac0ac4e2a70b1419b2ceec49 @weppos committed Nov 26, 2010
Showing with 37 additions and 27 deletions.
  1. +15 −0 spec/spec_helper.rb
  2. +19 −20 spec/whois/client_spec.rb
  3. +3 −7 spec/whois/errors_spec.rb
View
15 spec/spec_helper.rb
@@ -1,14 +1,29 @@
require "rspec"
require "whois"
+unless defined?(SPEC_ROOT)
+ SPEC_ROOT = Pathname.new(File.dirname(__FILE__))
+end
+
module Helpers
+
+ # Temporary resets Server @@definitions
+ # to let the test setup a custom definition list.
def with_definitions(&block)
@_definitions = Whois::Server.definitions
Whois::Server.send :class_variable_set, :@@definitions, { :tld => [], :ipv4 =>[], :ipv6 => [] }
yield
ensure
Whois::Server.send :class_variable_set, :@@definitions, @_definitions
end
+
+ # Gets the currently described class.
+ # Conversely to +subject+, it returns the class
+ # instead of an instance.
+ def klass
+ described_class
+ end
+
end
module ConnectivityHelpers
View
39 spec/whois/client_spec.rb
@@ -2,24 +2,20 @@
describe Whois::Client do
- before(:each) do
- @client = Whois::Client.new
- end
-
context ".new" do
it "initializes the instance" do
- client = Whois::Client.new
- client.should be_instance_of(Whois::Client)
+ client = klass.new
+ client.should be_instance_of(klass)
end
it "accepts a timeout option" do
- client = Whois::Client.new(:timeout => 100)
+ client = klass.new(:timeout => 100)
client.timeout.should == 100
end
it "accepts a block" do
- Whois::Client.new do |client|
- client.should be_instance_of(Whois::Client)
+ klass.new do |client|
+ client.should be_instance_of(klass)
end
end
end
@@ -32,28 +28,28 @@
# http://redmine.ruby-lang.org/issues/show/2617
server.expects(:query).with(instance_of(String))
Whois::Server.expects(:guess).with(instance_of(String)).returns(server)
- @client.query(["google", ".", "com"])
+ klass.new.query(["google", ".", "com"])
end
it "detects email" do
lambda do
- @client.query("weppos@weppos.net")
+ klass.new.query("weppos@weppos.net")
end.should raise_error(Whois::ServerNotSupported)
end
it "works with domain with no whois" do
Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None)
lambda do
- @client.query("domain.nowhois")
+ klass.new.query("domain.nowhois")
end.should raise_error(Whois::NoInterfaceError, /no whois server/)
end
it "works with domain with web whois" do
Whois::Server.define(:tld, ".webwhois", nil, :adapter => Whois::Server::Adapters::Web, :web => "www.nic.test")
lambda do
- @client.query("domain.webwhois")
+ klass.new.query("domain.webwhois")
end.should raise_error(Whois::WebInterfaceError, /www\.nic\.test/)
end
@@ -64,8 +60,9 @@ def query(*args)
end
end
Whois::Server.expects(:guess).returns(server.new)
- @client.timeout = 1
- lambda { @client.query("foo.com") }.should raise_error(Timeout::Error)
+
+ client = klass.new(:timeout => 1)
+ lambda { client.query("foo.com") }.should raise_error(Timeout::Error)
end
it "doesn't raise if timeout is not exceeded" do
@@ -75,8 +72,9 @@ def query(*args)
end
end
Whois::Server.expects(:guess).returns(server.new)
- @client.timeout = 5
- lambda { @client.query("foo.com") }.should_not raise_error
+
+ client = klass.new(:timeout => 5)
+ lambda { client.query("foo.com") }.should_not raise_error
end
it "supports unlimited timeout" do
@@ -86,8 +84,9 @@ def query(*args)
end
end
Whois::Server.expects(:guess).returns(server.new)
- @client.timeout = nil
- lambda { @client.query("foo.com") }.should_not raise_error
+
+ client = klass.new.tap { |c| c.timeout = nil }
+ lambda { client.query("foo.com") }.should_not raise_error
end
end
@@ -96,7 +95,7 @@ def query(*args)
need_connectivity do
describe "#query" do
it "sends a query for given domain" do
- answer = @client.query("weppos.it")
+ answer = klass.new.query("weppos.it")
assert answer.match?(/Domain:\s+weppos\.it/)
assert answer.match?(/Created:/)
end
View
10 spec/whois/errors_spec.rb
@@ -2,23 +2,19 @@
describe Whois::WebInterfaceError do
- before(:each) do
- @klass = Whois::WebInterfaceError
- end
-
describe ".new" do
it "sets the URL" do
- @klass.new("http://example.com").url.should == "http://example.com"
+ klass.new("http://example.com").url.should == "http://example.com"
end
it "requires the URL argument" do
- lambda { @klass.new }.should raise_error(ArgumentError)
+ lambda { klass.new }.should raise_error(ArgumentError)
end
end
describe "#message" do
it "interpolates the URL" do
- @klass.new("http://example.com").message.should match(%r{http://example.com})
+ klass.new("http://example.com").message.should match(%r{http://example.com})
end
end

0 comments on commit 5b012c3

Please sign in to comment.
Something went wrong with that request. Please try again.