Skip to content

Commit

Permalink
ensure the eq matcher sends :== to actual (not expected)
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jun 25, 2012
1 parent 49dc451 commit a3e2839
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/matchers/built_in/eq.rb
Expand Up @@ -3,7 +3,7 @@ module Matchers
module BuiltIn
class Eq < BaseMatcher
def match(expected, actual)
expected == actual
actual == expected
end

def failure_message_for_should
Expand Down
20 changes: 16 additions & 4 deletions spec/rspec/matchers/eq_spec.rb
Expand Up @@ -14,23 +14,35 @@ module Matchers
it "does not match when actual != expected" do
1.should_not eq(2)
end


it "compares by sending == to actual (not expected)" do
called = false
actual = Class.new do
define_method :== do |other|
called = true
end
end.new

actual.should eq :anything # to trigger the matches? method
called.should be_true
end

it "describes itself" do
matcher = eq(1)
matcher.matches?(1)
matcher.description.should == "eq 1"
matcher.description.should eq "eq 1"
end

it "provides message, expected and actual on #failure_message" do
matcher = eq("1")
matcher.matches?(1)
matcher.failure_message_for_should.should == "\nexpected: \"1\"\n got: 1\n\n(compared using ==)\n"
matcher.failure_message_for_should.should eq "\nexpected: \"1\"\n got: 1\n\n(compared using ==)\n"
end

it "provides message, expected and actual on #negative_failure_message" do
matcher = eq(1)
matcher.matches?(1)
matcher.failure_message_for_should_not.should == "\nexpected: value != 1\n got: 1\n\n(compared using ==)\n"
matcher.failure_message_for_should_not.should eq "\nexpected: value != 1\n got: 1\n\n(compared using ==)\n"
end
end
end
Expand Down

0 comments on commit a3e2839

Please sign in to comment.