diff --git a/lib/rspec/matchers/built_in/eq.rb b/lib/rspec/matchers/built_in/eq.rb index 1ebae0bbd..c6f6c3e7a 100644 --- a/lib/rspec/matchers/built_in/eq.rb +++ b/lib/rspec/matchers/built_in/eq.rb @@ -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 diff --git a/spec/rspec/matchers/eq_spec.rb b/spec/rspec/matchers/eq_spec.rb index b5523a180..9863ee118 100644 --- a/spec/rspec/matchers/eq_spec.rb +++ b/spec/rspec/matchers/eq_spec.rb @@ -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