Permalink
Browse files

BaseMatcher#== delegates to matches?

  • Loading branch information...
1 parent 88d6ecf commit 4499f5303b349139de25412b9dcdee3d436e2cbc @dchelimsky dchelimsky committed Nov 25, 2011
Showing with 23 additions and 0 deletions.
  1. +6 −0 lib/rspec/matchers/base_matcher.rb
  2. +17 −0 spec/rspec/matchers/base_matcher_spec.rb
@@ -1,5 +1,7 @@
module RSpec
module Matchers
+ # @api private
+ #
# Used _internally_ as a base class for matchers that ship with
# rspec-expectations.
#
@@ -45,6 +47,10 @@ def description
def diffable?
false
end
+
+ def ==(other)
+ matches?(other)
+ end
end
end
end
@@ -31,6 +31,23 @@ module RSpec::Matchers
matcher.rescued_exception.should be_a(RuntimeError)
matcher.rescued_exception.message.should eq("foo")
end
+
+ end
+
+ describe "#==" do
+ it "responds the same way as matches?" do
+ matcher = Class.new do
+ include BaseMatcher
+ def matches?(actual)
+ actual == expected
+ end
+ end
+ matcher.new(3).matches?(3).should be_true
+ matcher.new(3).should eq(3)
+
+ matcher.new(3).matches?(4).should be_false
+ matcher.new(3).should_not eq(4)
+ end
end
end
end

0 comments on commit 4499f53

Please sign in to comment.