Skip to content

Commit

Permalink
BaseMatcher#== delegates to matches?
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 25, 2011
1 parent 88d6ecf commit 4499f53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rspec/matchers/base_matcher.rb
@@ -1,5 +1,7 @@
module RSpec
module Matchers
# @api private
#
# Used _internally_ as a base class for matchers that ship with
# rspec-expectations.
#
Expand Down Expand Up @@ -45,6 +47,10 @@ def description
def diffable?
false
end

def ==(other)
matches?(other)
end
end
end
end
17 changes: 17 additions & 0 deletions spec/rspec/matchers/base_matcher_spec.rb
Expand Up @@ -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.