test/answer_test.rb in whois-0.8.1 vs test/answer_test.rb in whois-0.9.0
- old
+ new
@@ -1,9 +1,9 @@
require 'test_helper'
class AnswerTest < Test::Unit::TestCase
-
+
def setup
@klass = Whois::Answer
@server = Whois::Server.factory(:tld, ".foo", "whois.foo")
@parts = [
Whois::Answer::Part.new("This is a answer for domain.foo.", "foo.whois.com"),
@@ -18,11 +18,11 @@
answer = @klass.new(@server, @parts)
assert_instance_of @klass, answer
assert_equal @server, answer.server
assert_equal @parts, answer.parts
end
-
+
def test_initialize_should_require_server
assert_raise(ArgumentError) { @klass.new }
end
def test_initialize_should_require_parts
@@ -31,22 +31,27 @@
def test_to_s
assert_equal @content, @answer.to_s
end
-
+
def test_inspect
assert_equal @content.inspect, @answer.inspect
end
-
+
def test_match
# Force .to_a otherwise Match will be compared as Object instance
# and the test will fail because they actually are different instances.
assert_equal @content.match(/domain\.foo/).to_a, @answer.match(/domain\.foo/).to_a
assert_equal @content.match(/google/), @answer.match(/google/)
end
+ def test_match?
+ assert @answer.match?(/domain\.foo/)
+ assert !@answer.match?(/google/)
+ end
+
def test_equality_check_self
assert_equal @answer, @answer
assert @answer.eql?(@answer)
end
@@ -69,31 +74,40 @@
def test_content
answer = @klass.new(@server, @parts)
assert_equal @content, answer.content
end
- def test_match?
- assert @answer.match?(/domain\.foo/)
- assert !@answer.match?(/google/)
- end
-
def test_parser
answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
assert_instance_of Whois::Answer::Parser, answer.parser
answer = @klass.new(nil, [])
assert_instance_of Whois::Answer::Parser, answer.parser
end
- def test_supported?
+ def test_properties
answer = @klass.new(nil, [])
- answer.parser.expects(:supported?).with(:disclaimer).returns(:value)
- assert_equal :value, answer.supported?(:disclaimer)
+ answer.parser.expects(:property_supported?).with(:domain).returns(true)
+ answer.parser.expects(:property_supported?).with(:domain_id).returns(true)
+ answer.parser.expects(:property_supported?).with(Not(any_of(:domain, :domain_id))).at_least(1).returns(false)
+ answer.parser.expects(:domain).returns("foo.com")
+ answer.parser.expects(:domain_id).returns(27)
+
+ properties = answer.properties
+ assert_equal 2, properties.keys.length
+ assert_equal "foo.com", properties[:domain]
+ assert_equal 27, properties[:domain_id]
end
+ def test_property_supported?
+ answer = @klass.new(nil, [])
+ answer.parser.expects(:property_supported?).with(:disclaimer).returns(:value)
+ assert_equal :value, answer.property_supported?(:disclaimer)
+ end
- Whois::Answer::Parser.registrable_methods.each do |method|
+
+ Whois::Answer::Parser.properties.each do |method|
define_method "test_should_delegate_#{method}_to_parser" do
answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
parser = answer.parser
parser.expects(method).returns(:value)
assert_equal :value, answer.send(method)
\ No newline at end of file