[rspec-devel] [ rspec-Patches-14208 ] Fix to Mock#method_missing raising NameErrors instead of MockExpectationErrors
noreply at rubyforge.org
noreply at rubyforge.org
Tue Oct 2 03:22:36 EDT 2007
Patches item #14208, was opened at 2007-09-25 05:45
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14208&group_id=797
Category: None
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Antti Tarvainen (tarvaina)
>Assigned to: David Chelimsky (dchelimsky)
Summary: Fix to Mock#method_missing raising NameErrors instead of MockExpectationErrors
Initial Comment:
This patch fixes the nasty heisenbug in mock.rb.
Symptom:
--------
Every now and then mocks would throw NameErrors instead of MockExpectationErrors when they received unexpected method calls -- but sure enough, not when running the program in a debugger.
Cause:
------
Ruby's Object#method_missing throws either NameErrors or NoMethodErrors.
On a fresh ruby program Object#method_missing raises:
* NoMethodError when called directly (object.method_missing :foo)
* NameError when called indirectly (object.foo)
Once Object#method_missing has been called at least once (on any object)
it starts raising:
* NameError when called directly
* NameError when called indirectly
It is also possible for method_missing to go back to the original state, but I don't know when this happens.
Why Object#method_missing behaves this way, I have no idea. The version of Ruby I use is ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1].
Mock#method_missing relied on the assumption that calling Object#method_missing directly causes a NoMethodError to be raised.
Fix:
----
Mock#method_missing now converts all kinds of NameErrors (instead of just NoMethodErrors) into MockExpectationErrors.
----------------------------------------------------------------------
>Comment By: David Chelimsky (dchelimsky)
Date: 2007-10-02 07:22
Message:
Applied to r2683.
Thank so much for fixing this one!
----------------------------------------------------------------------
Comment By: Antti Tarvainen (tarvaina)
Date: 2007-09-25 05:47
Message:
Here's a test/unit test case that illustrates the weird
behavior of Object#method_missing.
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14208&group_id=797
More information about the rspec-devel
mailing list