Permalink
Browse files

Normalize, test and implement #throttle? and #incomplete?

  • Loading branch information...
1 parent 18051e2 commit 15415abdd3fc06300f9745daf711d574241bfa97 @weppos committed Jan 28, 2011
View
@@ -206,9 +206,19 @@ def contacts
#
# @see Whois::Answer::Parser#throttle?
#
- # def throttle?
- # parser.throttle?
- # end
+ def throttle?
+ parser.throttle?
+ end
+
+ # Checks whether this is an incomplete response.
+ #
+ # @return [Boolean]
+ #
+ # @see Whois::Answer::Parser#incomplete?
+ #
+ def incomplete?
+ parser.incomplete?
+ end
private
View
@@ -31,7 +31,7 @@ class Parser
METHODS = [
:changed?, :unchanged?,
:contacts,
- # :throttle?,
+ # :throttle?, :incomplete?,
]
PROPERTIES = [
@@ -121,17 +121,29 @@ def contacts
end
- # Loop through all the answer parts to check if at least
+ # Loop through all the parts to check if at least
# one part is a throttle response.
#
# @return [Boolean]
#
# @see Whois::Answer#throttle?
# @see Whois::Answer::Parser::Base#throttle?
#
- # def throttle?
- # parsers.any?(&:throttle?)
- # end
+ def throttle?
+ parsers.any?(&:throttle?)
+ end
+
+ # Loop through all the parts to check if at least
+ # one part is an incomplete response.
+ #
+ # @return [Boolean]
+ #
+ # @see Whois::Answer#incomplete?
+ # @see Whois::Answer::Parser::Base#incomplete?
+ #
+ def incomplete?
+ parsers.any?(&:incomplete?)
+ end
private
@@ -293,6 +293,20 @@ def throttle?
nil
end
+ # Checks whether this is an incomplete response.
+ # The default implementation always returns +nil+.
+ #
+ # @return [nil, false]
+ #
+ # @abstract This method returns nil by default.
+ #
+ # @see Whois::Answer#incomplete?
+ # @see Whois::Answer::Parser#incomplete?
+ #
+ def incomplete?
+ nil
+ end
+
protected
@@ -77,16 +77,6 @@ class WhoisCozaNetZa < Base
property_not_supported :nameservers
-
- protected
-
- # Very often the .to server returns a partial response, which is a response
- # containing an emtpy line.
- # It seems to be a very poorly-designed throttle mecanism.
- def incomplete_response?
- content_for_scanner.strip == ""
- end
-
end
end
@@ -42,8 +42,8 @@ class WhoisTonicTo < Base
property_supported :status do
- @status ||= if incomplete_response?
- :unknown
+ @status ||= if incomplete?
+ :incomplete
else
if available?
:available
@@ -54,11 +54,11 @@ class WhoisTonicTo < Base
end
property_supported :available? do
- @available ||= (!incomplete_response? && !!(content_for_scanner =~ /No match for/))
+ @available ||= (!incomplete? && !!(content_for_scanner =~ /No match for/))
end
property_supported :registered? do
- @registered ||= (!incomplete_response? && !available?)
+ @registered ||= (!incomplete? && !available?)
end
@@ -82,13 +82,24 @@ class WhoisTonicTo < Base
property_not_supported :nameservers
+ # Very often the .to server returns a partial response,
+ # which is a response containing an empty line.
+ # It seems to be a very poorly-designed throttle mechanism.
+ #
+ # @return [Boolean]
+ #
+ # @see Whois::Answer::Parser::Base#incomplete?
+ #
+ def incomplete?
+ content_for_scanner.strip == ""
+ end
+
+
protected
- # Very often the .to server returns a partial response, which is a response
- # containing an emtpy line.
- # It seems to be a very poorly-designed throttle mecanism.
def incomplete_response?
- content_for_scanner.strip == ""
+ Whois.deprecate "#{self.class}#incomplete? will be removed in Whois 2.1. Please use #{self.class}#incomplete?."
+ incomplete?
end
end
@@ -146,6 +146,7 @@
end
end
+
describe "#throttle?" do
it "returns nil" do
i = klass.new(@part)
@@ -158,4 +159,16 @@
end
end
+ describe "#incomplete?" do
+ it "returns nil" do
+ i = klass.new(@part)
+ i.incomplete?.should be_nil
+ end
+
+ it "is false" do
+ i = klass.new(@part)
+ i.incomplete?.should be_false
+ end
+ end
+
end
@@ -164,10 +164,48 @@ class Whois::Answer::Parser::ParserUnsupportedTest < Whois::Answer::Parser::Base
end
- # describe "#throttle?" do
- # it "" do
- # end
- # end
+ describe "#throttle?" do
+ it "returns false when all parts are not throttled" do
+ i = double_parser
+ i.parsers[0].expects(:throttle?).returns(false)
+ i.parsers[1].expects(:throttle?).returns(false)
+ i.throttle?.should == false
+ end
+
+ it "returns true when at least one part is throttled" do
+ i = double_parser
+ i.parsers[0].expects(:throttle?).returns(false)
+ i.parsers[1].expects(:throttle?).returns(true)
+ i.throttle?.should == true
+
+ i = double_parser
+ i.parsers[0].expects(:throttle?).returns(true)
+ i.parsers[1].expects(:throttle?).never
+ i.throttle?.should == true
+ end
+ end
+
+
+ describe "#incomplete?" do
+ it "returns false when all parts are complete" do
+ i = double_parser
+ i.parsers[0].expects(:incomplete?).returns(false)
+ i.parsers[1].expects(:incomplete?).returns(false)
+ i.incomplete?.should == false
+ end
+
+ it "returns true when at least one part is incomplete" do
+ i = double_parser
+ i.parsers[0].expects(:incomplete?).returns(false)
+ i.parsers[1].expects(:incomplete?).returns(true)
+ i.incomplete?.should == true
+
+ i = double_parser
+ i.parsers[0].expects(:incomplete?).returns(true)
+ i.parsers[1].expects(:incomplete?).never
+ i.incomplete?.should == true
+ end
+ end
describe ".parser_klass" do
@@ -201,4 +239,11 @@ class PreloadedParserTest
end
end
+
+ private
+
+ def double_parser
+ klass.new(Whois::Answer.new(nil, [Whois::Answer::Part.new("successful", "whois.test"), Whois::Answer::Part.new("successful", "whois.test")]))
+ end
+
end
View
@@ -305,14 +305,21 @@ class Whois::Answer::Parser::WhoisPropertiesTest < Whois::Answer::Parser::Base
end
- # describe "#throttle?" do
- # it "delegates to #parser" do
- # i = klass.new(nil, @parts)
- # i.parser.expects(:throttle?)
- #
- # i.throttle?
- # end
- # end
+ describe "#throttle?" do
+ it "delegates to #parser" do
+ i = klass.new(nil, [])
+ i.parser.expects(:throttle?)
+ i.throttle?
+ end
+ end
+
+ describe "#incomplete?" do
+ it "delegates to #parser" do
+ i = klass.new(nil, [])
+ i.parser.expects(:incomplete?)
+ i.incomplete?
+ end
+ end
describe "method_missing" do
Oops, something went wrong.

0 comments on commit 15415ab

Please sign in to comment.