Permalink
Browse files

Merge pull request #323 from rspec/fix_operator_matcher_regression

Fix operator matcher when operator implemented via method_missing
  • Loading branch information...
2 parents 8a553b4 + a75c8d3 commit 461fdfd6213887988b7ea952fb6724627d8557e1 @JonRowe JonRowe committed Sep 9, 2013
Showing with 20 additions and 0 deletions.
  1. +2 −0 Changelog.md
  2. +2 −0 lib/rspec/matchers/operator_matcher.rb
  3. +16 −0 spec/rspec/matchers/operator_matcher_spec.rb
View
2 Changelog.md
@@ -22,6 +22,8 @@ Bug fixes
* Fix operator matchers (`should` syntax) when `method` is redefined on target.
(Brandon Turner)
* Fix diffing of hashes with object based keys. (Jon Rowe)
+* Fix operator matchers (`should` syntax) when operator is defined via
+ `method_missing` (Jon Rowe)
### 2.14.2 / 2013-08-14
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2)
View
2 lib/rspec/matchers/operator_matcher.rb
@@ -64,6 +64,8 @@ def description
def uses_generic_implementation_of?(op)
Expectations.method_handle_for(@actual, op).owner == ::Kernel
+ rescue NameError
+ false
end
def eval_match(actual, operator, expected)
View
16 spec/rspec/matchers/operator_matcher_spec.rb
@@ -6,6 +6,14 @@ def method
end
end
+class MethodMissingObject < Struct.new(:original)
+ undef ==
+
+ def method_missing(name, *args, &block)
+ original.__send__ name, *args, &block
+ end
+end
+
describe "operator matchers", :uses_should do
describe "should ==" do
it "delegates message to target" do
@@ -31,6 +39,14 @@ def method
myobj.should == myobj
}.to_not raise_error
end
+
+ it "works when implemented via method_missing" do
+ obj = Object.new
+
+ myobj = MethodMissingObject.new(obj)
+ myobj.should == obj
+ myobj.should_not == Object.new
+ end
end
describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do

0 comments on commit 461fdfd

Please sign in to comment.