Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecated the comparison of Whois::Answer with String.

  • Loading branch information...
commit a302996dbacd77ed0267e33833617dfd8ed6681f 1 parent 1ca6d97
Simone Carletti authored
2  CHANGELOG.rdoc
View
@@ -19,6 +19,8 @@
* CHANGED: Whois::Server::Adapter::Base#== now returns false if other is not the same instance of self.
+* CHANGED: Deprecated the comparison of Whois::Answer with String.
+
* FIXED: Converted #changed? and #unchanged? properties to methods
and normalized their behavior.
38 lib/whois/answer.rb
View
@@ -54,6 +54,28 @@ def inspect
content.inspect
end
+ # Returns true if the <tt>object</tt> is the same object,
+ # or is a string and has the same content.
+ #
+ # @param [Whois::Answer] other The answer to compare.
+ # @return [Boolean]
+ def ==(other)
+ if equal?(other)
+ return true
+ end
+ if other.is_a?(self.class)
+ return to_s == other.to_s
+ end
+ if other.is_a?(String)
+ Whois.deprecate "Comparing an answer with a String is deprecated and will be removed in Whois 2.1."
+ return to_s == other.to_s
+ end
+ false
+ end
+
+ alias_method :eql?, :==
+
+
# Invokes {#match} on answer {#content}
# and returns the match as <tt>MatchData</tt> or <tt>nil</tt>.
#
@@ -79,22 +101,6 @@ def match?(pattern)
!content.match(pattern).nil?
end
- # Returns true if the <tt>object</tt> is the same object,
- # or is a string and has the same content.
- #
- # @param [Whois::Answer] other The answer to compare.
- # @return [Boolean]
- #
- def ==(other)
- (self.equal?(other)) ||
- # TODO: This option should be deprecated
- (other.is_a?(String) && to_s == other) ||
- (other.is_a?(Answer) && to_s == other.to_s)
- end
-
- alias_method :eql?, :==
-
-
# Joins and returns all answer parts into a single string
# and separates each response with a newline character.
#
65 spec/whois/answer_spec.rb
View
@@ -13,6 +13,71 @@
end
+ describe "#==" do
+ it "returns true when other is the same instance" do
+ one = two = klass.new(@server, @parts)
+
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
+ it "returns true when other has same class and has the same parts" do
+ one, two = klass.new(@server, @parts), klass.new(@server, @parts)
+
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
+ it "returns true when other has descendant class and has the same parts" do
+ subklass = Class.new(klass)
+ one, two = klass.new(@server, @parts), subklass.new(@server, @parts)
+
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
+ it "returns true when other has same class and has equal parts" do
+ one, two = klass.new(@server, @parts), klass.new(@server, @parts.dup)
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
+ it "returns true when other has same class, different server and the same parts" do
+ one, two = klass.new(@server, @parts), klass.new(nil, @parts)
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
+ it "returns false when other has different class and has the same parts" do
+ one, two = klass.new(@server, @parts), Struct.new(:server, :parts).new(@server, @parts)
+
+ (one == two).should be_false
+ (one.eql? two).should be_false
+ end
+
+ it "returns false when other has different parts" do
+ one, two = klass.new(@server, @parts), klass.new(@server, [])
+
+ (one == two).should be_false
+ (one.eql? two).should be_false
+ end
+
+ it "returns true when other is string and has the same content", :deprecated => true do
+ one, two = klass.new(@server, @parts), klass.new(@server, @parts).to_s
+
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
+ it "returns false when other is string and has different content", :deprecated => true do
+ one, two = klass.new(@server, @parts), "different"
+
+ (one == two).should be_false
+ (one.eql? two).should be_false
+ end
+ end
+
+
describe "#changed?" do
it "raises if the argument is not an instance of the same class" do
lambda do
8 spec/whois/server/adapters/base_spec.rb
View
@@ -47,6 +47,14 @@
(one.eql? two).should be_true
end
+ it "returns true when other has descendant class and has the same attributes" do
+ subklass = Class.new(klass)
+ one, two = klass.new(*@definition), subklass.new(*@definition)
+
+ (one == two).should be_true
+ (one.eql? two).should be_true
+ end
+
it "returns false when other has different class and has the same attributes" do
one, two = klass.new(*@definition), Struct.new(:type, :allocation, :host, :options).new(*@definition)
32 test/whois/answer_test.rb
View
@@ -50,38 +50,6 @@ def test_match?
assert !@answer.match?(/google/)
end
- def test_equality_with_check_self
- assert_equal @answer, @answer
- assert @answer.eql?(@answer)
- end
-
- def test_equality_with_check_self_class
- assert_equal @answer, @answer.dup
- assert @answer.eql?(@answer.dup)
- end
-
- def test_equality_with_check_self_subclass
- child = Class.new(@klass)
-
- assert_equal @answer, child.new(@answer.server, @answer.parts)
- assert @answer.eql?(child.new(@answer.server, @answer.parts))
- end
-
- def test_equality_with_check_string
- assert_equal @answer, @content
- assert_not_equal @content, @answer
- assert @answer.eql?(@content)
- assert !@content.eql?(@answer)
- end
-
- def test_equality_check_content
- other = @klass.new(@server, @parts)
- assert_equal @answer, other
- assert_equal other, @answer
- assert @answer.eql?(other)
- assert other.eql?(@answer)
- end
-
def test_content
answer = @klass.new(@server, @parts)
Please sign in to comment.
Something went wrong with that request. Please try again.