test/answer_test.rb in whois-0.9.0 vs test/answer_test.rb in whois-1.0.0
- old
+ new
@@ -83,36 +83,72 @@
answer = @klass.new(nil, [])
assert_instance_of Whois::Answer::Parser, answer.parser
end
+
+ class Whois::Answer::Parser::WhoisParserFake < Whois::Answer::Parser::Base
+ property_supported :status do
+ nil
+ end
+ property_supported :created_on do
+ Date.parse("2010-10-20")
+ end
+ property_not_supported :updated_on
+ # property_not_defined :expires_on
+ end
+
+ def test_property_supported?
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert answer.property_supported?(:status)
+ assert answer.property_supported?(:created_on)
+ assert !answer.property_supported?(:updated_on)
+ assert !answer.property_supported?(:expires_on)
+ end
+
def test_properties
- answer = @klass.new(nil, [])
- 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)
-
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
properties = answer.properties
- assert_equal 2, properties.keys.length
- assert_equal "foo.com", properties[:domain]
- assert_equal 27, properties[:domain_id]
+
+ assert_equal Whois::Answer::Parser.properties.size, properties.keys.size
+ assert_equal nil, properties[:status]
+ assert_equal Date.parse("2010-10-20"), properties[:created_on]
+ assert_equal nil, properties[:updated_on]
+ assert_equal nil, properties[:expires_on]
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)
+ def test_should_return_value_with_supported_property_getter
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert_equal Date.parse("2010-10-20"), answer.created_on
end
+ def test_should_return_nil_with_not_supported_property_getter
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert_equal nil, answer.updated_on
+ end
- 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)
- end
+ def test_should_return_nil_with_not_implemented_property
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert_equal nil, answer.expires_on
+ end
+
+ def test_should_return_false_with_supported_property_getter_and_not_value
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert !answer.status?
+ end
+
+ def test_should_return_true_with_supported_property_getter_and_value
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert answer.created_on?
+ end
+
+ def test_should_return_false_with_not_supported_property_exists
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert !answer.updated_on?
+ end
+
+ def test_should_return_false_with_not_implemented_property_exists
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.parser.fake")])
+ assert !answer.expires_on?
end
end
\ No newline at end of file