Permalink
Browse files

Convert Test::Unit to RSpec.

  • Loading branch information...
1 parent 371c41d commit 45806c56f830658e490a6de81cd2213a4952386e @weppos committed Nov 21, 2010
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
- before :each do
+ before(:each) do
@client = Whois::Client.new
end
context ".new" do
- it "should initialize" do
+ it "initializes the instance" do
client = Whois::Client.new
client.should be_instance_of(Whois::Client)
end
- it "should initialize with timeout" do
+ it "accepts a timeout option" do
client = Whois::Client.new(:timeout => 100)
client.timeout.should == 100
end
- it "should initialize with block" do
+ it "accepts a block" do
Whois::Client.new do |client|
client.should be_instance_of(Whois::Client)
end
end
end
context "#query" do
- it "should coerce qstring to string" do
+ it "coerces qstring to string" do
server = Object.new
# I can't use the String because Array#to_s behaves differently
# on Ruby 1.8.7 and Ruby 1.9.1
@@ -35,28 +35,29 @@
@client.query(["google", ".", "com"])
end
- it "should detect email" do
- lambda { @client.query("weppos@weppos.net") }.should
- raise_error(Whois::ServerNotSupported)
+ it "detects email" do
+ lambda do
+ @client.query("weppos@weppos.net")
+ end.should raise_error(Whois::ServerNotSupported)
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)
- lambda { @client.query("domain.nowhois") }.should
- raise_error(Whois::NoInterfaceError, /no whois server/)
+ lambda do
+ @client.query("domain.nowhois")
+ end.should raise_error(Whois::NoInterfaceError, /no whois server/)
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")
- lambda { @client.query("domain.webwhois") }.should raise_error(Whois::WebInterfaceError) do |error|
- error.message.should match(/no whois server/)
- error.message.should match(/www\.nic\.test/)
- end
+ lambda do
+ @client.query("domain.webwhois")
+ end.should raise_error(Whois::WebInterfaceError, /www\.nic\.test/)
end
- it "should raise if timeout is exceeded" do
+ it "raises if timeout is exceeded" do
server = Class.new do
def query(*args)
sleep(2)
@@ -67,7 +68,7 @@ def query(*args)
lambda { @client.query("foo.com") }.should raise_error(Timeout::Error)
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
def query(*args)
sleep(1)
@@ -78,7 +79,7 @@ def query(*args)
lambda { @client.query("foo.com") }.should_not raise_error
end
- it "should support unlimited timeout" do
+ it "supports unlimited timeout" do
server = Class.new do
def query(*args)
sleep(1)
@@ -91,11 +92,14 @@ def query(*args)
end
+ # FIXME: use RSpec metadata
need_connectivity do
- specify "#query with domain" do
- answer = @client.query("weppos.it")
- assert answer.match?(/Domain:\s+weppos\.it/)
- assert answer.match?(/Created:/)
+ describe "#query" do
+ it "sends a query for given domain" do
+ answer = @client.query("weppos.it")
+ assert answer.match?(/Domain:\s+weppos\.it/)
+ assert answer.match?(/Created:/)
+ 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
describe ".available?" do
- it "should query domain and return true" do
+ it "queries the domain and returns true" do
with_definitions do
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")
@@ -21,7 +21,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end
end
- it "should query domain and return false" do
+ it "queries the domain and returns false" do
with_definitions do
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")
@@ -30,7 +30,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end
end
- it "should return nil with missing parser" do
+ it "returns nil with missing parser" do
with_definitions do
Whois::Server.define(:tld, ".test", "missing.parser.test")
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
describe ".registered?" do
- it "should query domain and return false" do
+ it "queries the domain and returns false" do
with_definitions do
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")
@@ -50,7 +50,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end
end
- it "should query domain and return true" do
+ it "queries the domain and returns true" do
with_definitions do
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")
@@ -59,7 +59,7 @@ class Whois::Answer::Parser::ParserTest < Whois::Answer::Parser::Base
end
end
- it "should return nil with missing parser" do
+ it "returns nil with missing parser" do
with_definitions do
Whois::Server.define(:tld, ".test", "missing.parser.test")
Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).returns("1 == 2")
View
@@ -1,23 +0,0 @@
-require 'test_helper'
-
-class WebInterfaceErrorTest < Test::Unit::TestCase
-
- def setup
- @klass = Whois::WebInterfaceError
- end
-
- def test_url
- assert_raise(ArgumentError) { @klass.new }
- end
-
- def test_url
- error = @klass.new("http://example.com")
- assert_equal "http://example.com", error.url
- end
-
- def test_message
- error = @klass.new("http://example.com")
- assert_match %r{http://example.com}, error.message
- end
-
-end

0 comments on commit 45806c5

Please sign in to comment.