Permalink
Browse files

Convert Test to RSpec.

  • Loading branch information...
weppos committed Dec 13, 2010
1 parent 3ed42c6 commit 194c20588ac95cff63f234f6888aa4579ce852e9
@@ -0,0 +1,57 @@
+require "spec_helper"
+
+describe Whois::Answer::Contact do
+
+ it "inherits from SuperStruct" do
+ klass.ancestors.should include(SuperStruct)
+ end
+
+
+ describe ".new" do
+ it "accepts an empty value" do
+ lambda do
+ i = klass.new
+ i.id.should be_nil
+ end.should_not raise_error
+ end
+
+ it "accepts an empty hash" do
+ lambda do
+ i = klass.new({})
+ i.id.should be_nil
+ end.should_not raise_error
+ end
+
+ it "initializes a new instance from given params" do
+ i = klass.new(10, klass::TYPE_REGISTRANT, "John Doe", nil)
+
+ i.id.should == 10
+ i.type.should == klass::TYPE_REGISTRANT
+ i.name.should == "John Doe"
+ i.organization.should be_nil
+ end
+
+ it "initializes a new instance from given hash" do
+ i = klass.new(:id => 10, :name => "John Doe", :type => klass::TYPE_REGISTRANT)
+
+ i.id.should == 10
+ i.type.should == klass::TYPE_REGISTRANT
+ i.name.should == "John Doe"
+ i.organization.should be_nil
+ end
+
+ it "initializes a new instance from given block" do
+ i = klass.new do |c|
+ c.id = 10
+ c.type = klass::TYPE_REGISTRANT
+ c.name = "John Doe"
+ end
+
+ i.id.should == 10
+ i.type.should == klass::TYPE_REGISTRANT
+ i.name.should == "John Doe"
+ i.organization.should be_nil
+ end
+ end
+
+end
@@ -0,0 +1,53 @@
+require "spec_helper"
+
+describe Whois::Answer::Nameserver do
+
+ it "inherits from SuperStruct" do
+ klass.ancestors.should include(SuperStruct)
+ end
+
+
+ describe ".new" do
+ it "accepts an empty value" do
+ lambda do
+ i = klass.new
+ i.name.should be_nil
+ end.should_not raise_error
+ end
+
+ it "accepts an empty hash" do
+ lambda do
+ i = klass.new({})
+ i.name.should be_nil
+ end.should_not raise_error
+ end
+
+ it "initializes a new instance from given params" do
+ i = klass.new("ns1.example.com", "127.0.0.1")
+
+ i.name.should == "ns1.example.com"
+ i.ipv4.should == "127.0.0.1"
+ i.ipv6.should be_nil
+ end
+
+ it "initializes a new instance from given hash" do
+ i = klass.new(:name => "ns1.example.com", :ipv4 => "127.0.0.1")
+
+ i.name.should == "ns1.example.com"
+ i.ipv4.should == "127.0.0.1"
+ i.ipv6.should be_nil
+ end
+
+ it "initializes a new instance from given block" do
+ i = klass.new do |c|
+ c.name = "ns1.example.com"
+ c.ipv4 = "127.0.0.1"
+ end
+
+ i.name.should == "ns1.example.com"
+ i.ipv4.should == "127.0.0.1"
+ i.ipv6.should be_nil
+ end
+ end
+
+end
@@ -0,0 +1,50 @@
+require "spec_helper"
+
+describe Whois::Answer::Part do
+
+ it "inherits from SuperStruct" do
+ klass.ancestors.should include(SuperStruct)
+ end
+
+
+ describe ".new" do
+ it "accepts an empty value" do
+ lambda do
+ i = klass.new
+ i.body.should be_nil
+ end.should_not raise_error
+ end
+
+ it "accepts an empty hash" do
+ lambda do
+ i = klass.new({})
+ i.body.should be_nil
+ end.should_not raise_error
+ end
+
+ it "initializes a new instance from given params" do
+ i = klass.new("This is a WHOIS record.", "whois.example.test")
+
+ i.body.should == "This is a WHOIS record."
+ i.host.should == "whois.example.test"
+ end
+
+ it "initializes a new instance from given hash" do
+ i = klass.new(:body => "This is a WHOIS record.", :host => "whois.example.test")
+
+ i.body.should == "This is a WHOIS record."
+ i.host.should == "whois.example.test"
+ end
+
+ it "initializes a new instance from given block" do
+ i = klass.new do |c|
+ c.body = "This is a WHOIS record."
+ c.host = "whois.example.test"
+ end
+
+ i.body.should == "This is a WHOIS record."
+ i.host.should == "whois.example.test"
+ end
+ end
+
+end
@@ -0,0 +1,57 @@
+require "spec_helper"
+
+describe Whois::Answer::Registrar do
+
+ it "inherits from SuperStruct" do
+ klass.ancestors.should include(SuperStruct)
+ end
+
+
+ describe ".new" do
+ it "accepts an empty value" do
+ lambda do
+ i = klass.new
+ i.id.should be_nil
+ end.should_not raise_error
+ end
+
+ it "accepts an empty hash" do
+ lambda do
+ i = klass.new({})
+ i.id.should be_nil
+ end.should_not raise_error
+ end
+
+ it "initializes a new instance from given params" do
+ i = klass.new(10, "John Doe", nil, "http://example.com")
+
+ i.id.should == 10
+ i.name.should == "John Doe"
+ i.organization.should be_nil
+ i.url.should == "http://example.com"
+ end
+
+ it "initializes a new instance from given hash" do
+ i = klass.new(:id => 10, :name => "John Doe", :url => "http://example.com")
+
+ i.id.should == 10
+ i.name.should == "John Doe"
+ i.organization.should be_nil
+ i.url.should == "http://example.com"
+ end
+
+ it "initializes a new instance from given block" do
+ i = klass.new do |c|
+ c.id = 10
+ c.name = "John Doe"
+ c.url = "http://example.com"
+ end
+
+ i.id.should == 10
+ i.name.should == "John Doe"
+ i.organization.should be_nil
+ i.url.should == "http://example.com"
+ end
+ end
+
+end
@@ -0,0 +1,28 @@
+require "spec_helper"
+
+describe SuperStruct do
+
+ SuperEroe = Class.new(SuperStruct.new(:name, :supername))
+
+ it "inherits from Struct" do
+ SuperEroe.ancestors.should include(Struct)
+ end
+
+
+ describe ".new" do
+ it "initializes a new instance from given hash" do
+ i = SuperEroe.new(:name => "Pippo", :supername => "SuperPippo")
+
+ i.name.should == "Pippo"
+ i.supername.should == "SuperPippo"
+ end
+
+ it "initializes a new instance from given block" do
+ SuperEroe.new do |i|
+ i.should be_instance_of(SuperEroe)
+ i.should be_kind_of(SuperStruct)
+ end
+ end
+ end
+
+end
@@ -1,50 +0,0 @@
-require 'test_helper'
-
-class Whois::Answer::ContactTest < Test::Unit::TestCase
-
- def setup
- @klass = Whois::Answer::Contact
- end
-
- def test_initialize_with_empty_values
- instance = @klass.new
- assert_instance_of @klass, instance
- assert_equal nil, instance.id
-
- instance = @klass.new({})
- assert_instance_of @klass, instance
- assert_equal nil, instance.id
- end
-
- def test_initialize_with_params
- instance = @klass.new(10, @klass::TYPE_REGISTRANT, "John Doe", nil)
-
- assert_equal 10, instance.id
- assert_equal @klass::TYPE_REGISTRANT, instance.type
- assert_equal "John Doe", instance.name
- assert_equal nil, instance.organization
- end
-
- def test_initialize_with_hash
- instance = @klass.new(:id => 10, :name => "John Doe", :type => @klass::TYPE_REGISTRANT)
-
- assert_equal 10, instance.id
- assert_equal @klass::TYPE_REGISTRANT, instance.type
- assert_equal "John Doe", instance.name
- assert_equal nil, instance.organization
- end
-
- def test_initialize_with_block
- instance = @klass.new do |c|
- c.id = 10
- c.type = @klass::TYPE_REGISTRANT
- c.name = "John Doe"
- end
-
- assert_equal 10, instance.id
- assert_equal @klass::TYPE_REGISTRANT, instance.type
- assert_equal "John Doe", instance.name
- assert_equal nil, instance.organization
- end
-
-end
@@ -1,46 +0,0 @@
-require 'test_helper'
-
-class Whois::Answer::NameserverTest < Test::Unit::TestCase
-
- def setup
- @klass = Whois::Answer::Nameserver
- end
-
- def test_initialize_with_empty_values
- instance = @klass.new
- assert_instance_of @klass, instance
- assert_equal nil, instance.name
-
- instance = @klass.new({})
- assert_instance_of @klass, instance
- assert_equal nil, instance.name
- end
-
- def test_initialize_with_params
- instance = @klass.new("ns1.example.com", "127.0.0.1")
-
- assert_equal "ns1.example.com", instance.name
- assert_equal "127.0.0.1", instance.ipv4
- assert_equal nil, instance.ipv6
- end
-
- def test_initialize_with_hash
- instance = @klass.new(:name => "ns1.example.com", :ipv4 => "127.0.0.1")
-
- assert_equal "ns1.example.com", instance.name
- assert_equal "127.0.0.1", instance.ipv4
- assert_equal nil, instance.ipv6
- end
-
- def test_initialize_with_block
- instance = @klass.new do |c|
- c.name = "ns1.example.com"
- c.ipv4 = "127.0.0.1"
- end
-
- assert_equal "ns1.example.com", instance.name
- assert_equal "127.0.0.1", instance.ipv4
- assert_equal nil, instance.ipv6
- end
-
-end
@@ -1,43 +0,0 @@
-require 'test_helper'
-
-class Whois::Answer::PartTest < Test::Unit::TestCase
-
- def setup
- @klass = Whois::Answer::Part
- end
-
- def test_initialize_with_empty_values
- instance = @klass.new
- assert_instance_of @klass, instance
- assert_equal nil, instance.body
-
- instance = @klass.new({})
- assert_instance_of @klass, instance
- assert_equal nil, instance.body
- end
-
- def test_initialize_with_params
- instance = @klass.new("This is a WHOIS record.", "whois.example.test")
-
- assert_equal "This is a WHOIS record.", instance.body
- assert_equal "whois.example.test", instance.host
- end
-
- def test_initialize_with_hash
- instance = @klass.new(:body => "This is a WHOIS record.", :host => "whois.example.test")
-
- assert_equal "This is a WHOIS record.", instance.body
- assert_equal "whois.example.test", instance.host
- end
-
- def test_initialize_with_block
- instance = @klass.new do |c|
- c.body = "This is a WHOIS record."
- c.host = "whois.example.test"
- end
-
- assert_equal "This is a WHOIS record.", instance.body
- assert_equal "whois.example.test", instance.host
- end
-
-end
Oops, something went wrong.

0 comments on commit 194c205

Please sign in to comment.