Permalink
Browse files

Convert Test::Unit to RSpec.

  • Loading branch information...
weppos committed Nov 21, 2010
1 parent 371c41d commit 45806c56f830658e490a6de81cd2213a4952386e
Showing with 58 additions and 52 deletions.
  1. +27 −23 spec/whois/client_spec.rb
  2. +25 −0 spec/whois/errors_spec.rb
  3. +6 −6 spec/whois/whois_spec.rb
  4. +0 −23 test/whois/errors_test.rb
View
@@ -2,30 +2,30 @@
describe Whois::Client do describe Whois::Client do
before :each do before(:each) do
@client = Whois::Client.new @client = Whois::Client.new
end end
context ".new" do context ".new" do
it "should initialize" do it "initializes the instance" do
client = Whois::Client.new client = Whois::Client.new
client.should be_instance_of(Whois::Client) client.should be_instance_of(Whois::Client)
end end
it "should initialize with timeout" do it "accepts a timeout option" do
client = Whois::Client.new(:timeout => 100) client = Whois::Client.new(:timeout => 100)
client.timeout.should == 100 client.timeout.should == 100
end end
it "should initialize with block" do it "accepts a block" do
Whois::Client.new do |client| Whois::Client.new do |client|
client.should be_instance_of(Whois::Client) client.should be_instance_of(Whois::Client)
end end
end end
end end
context "#query" do context "#query" do
it "should coerce qstring to string" do it "coerces qstring to string" do
server = Object.new server = Object.new
# I can't use the String because Array#to_s behaves differently # I can't use the String because Array#to_s behaves differently
# on Ruby 1.8.7 and Ruby 1.9.1 # on Ruby 1.8.7 and Ruby 1.9.1
@@ -35,28 +35,29 @@
@client.query(["google", ".", "com"]) @client.query(["google", ".", "com"])
end end
it "should detect email" do it "detects email" do
lambda { @client.query("weppos@weppos.net") }.should lambda do
raise_error(Whois::ServerNotSupported) @client.query("weppos@weppos.net")
end.should raise_error(Whois::ServerNotSupported)
end end
it "should work with domain with no whois" do it "works with domain with no whois" do
Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None) Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None)
lambda { @client.query("domain.nowhois") }.should lambda do
raise_error(Whois::NoInterfaceError, /no whois server/) @client.query("domain.nowhois")
end.should raise_error(Whois::NoInterfaceError, /no whois server/)
end end
it "should work with domain with web whois" do it "works with domain with web whois" do
Whois::Server.define(:tld, ".webwhois", nil, :adapter => Whois::Server::Adapters::Web, :web => "www.nic.test") Whois::Server.define(:tld, ".webwhois", nil, :adapter => Whois::Server::Adapters::Web, :web => "www.nic.test")
lambda { @client.query("domain.webwhois") }.should raise_error(Whois::WebInterfaceError) do |error| lambda do
error.message.should match(/no whois server/) @client.query("domain.webwhois")
error.message.should match(/www\.nic\.test/) end.should raise_error(Whois::WebInterfaceError, /www\.nic\.test/)
end
end end
it "should raise if timeout is exceeded" do it "raises if timeout is exceeded" do
server = Class.new do server = Class.new do
def query(*args) def query(*args)
sleep(2) sleep(2)
@@ -67,7 +68,7 @@ def query(*args)
lambda { @client.query("foo.com") }.should raise_error(Timeout::Error) lambda { @client.query("foo.com") }.should raise_error(Timeout::Error)
end end
it "should not raise if timeout is not exceeded" do it "doesn't raise if timeout is not exceeded" do
server = Class.new do server = Class.new do
def query(*args) def query(*args)
sleep(1) sleep(1)
@@ -78,7 +79,7 @@ def query(*args)
lambda { @client.query("foo.com") }.should_not raise_error lambda { @client.query("foo.com") }.should_not raise_error
end end
it "should support unlimited timeout" do it "supports unlimited timeout" do
server = Class.new do server = Class.new do
def query(*args) def query(*args)
sleep(1) sleep(1)
@@ -91,11 +92,14 @@ def query(*args)
end end
# FIXME: use RSpec metadata
need_connectivity do need_connectivity do
specify "#query with domain" do describe "#query" do
answer = @client.query("weppos.it") it "sends a query for given domain" do
assert answer.match?(/Domain:\s+weppos\.it/) answer = @client.query("weppos.it")
assert answer.match?(/Created:/) assert answer.match?(/Domain:\s+weppos\.it/)
assert answer.match?(/Created:/)
end
end end
end end
View
@@ -0,0 +1,25 @@
require "spec_helper"
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"
end
it "requires the URL argument" do
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})
end
end
end
View
@@ -12,7 +12,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end end
describe ".available?" do describe ".available?" do
it "should query domain and return true" do it "queries the domain and returns true" do
with_definitions do with_definitions do
Whois::Server.define(:tld, ".test", "parser.test") Whois::Server.define(:tld, ".test", "parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 1") Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 1")
@@ -21,7 +21,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end end
end end
it "should query domain and return false" do it "queries the domain and returns false" do
with_definitions do with_definitions do
Whois::Server.define(:tld, ".test", "parser.test") Whois::Server.define(:tld, ".test", "parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 2") Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 2")
@@ -30,7 +30,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end end
end end
it "should return nil with missing parser" do it "returns nil with missing parser" do
with_definitions do with_definitions do
Whois::Server.define(:tld, ".test", "missing.parser.test") Whois::Server.define(:tld, ".test", "missing.parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).returns("1 == 2") Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).returns("1 == 2")
@@ -41,7 +41,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end end
describe ".registered?" do describe ".registered?" do
it "should query domain and return false" do it "queries the domain and returns false" do
with_definitions do with_definitions do
Whois::Server.define(:tld, ".test", "parser.test") Whois::Server.define(:tld, ".test", "parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 1") Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 1")
@@ -50,7 +50,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end end
end end
it "should query domain and return true" do it "queries the domain and returns true" do
with_definitions do with_definitions do
Whois::Server.define(:tld, ".test", "parser.test") Whois::Server.define(:tld, ".test", "parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 2") Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("example.test", "parser.test").returns("1 == 2")
@@ -59,7 +59,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end end
end end
it "should return nil with missing parser" do it "returns nil with missing parser" do
with_definitions do with_definitions do
Whois::Server.define(:tld, ".test", "missing.parser.test") Whois::Server.define(:tld, ".test", "missing.parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).returns("1 == 2") Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).returns("1 == 2")
View

This file was deleted.

Oops, something went wrong.

0 comments on commit 45806c5

Please sign in to comment.