freerange/mocha — pull request #81 by floehopper (2012-05-14 07:53:01+00:00)
Title: Make it possible to serialize and deserialize a stub object.

Previously this was raising an exception because Mock#respond_to? was
being called before the instance of Mock has been re-hydrated i.e. none
of its instance variables had been set :-

NoMethodError: undefined method `matches_method?' for nil:NilClass
from gems/mocha-0.10.5/lib/mocha/mock.rb:185:in `respond_to?'

Note that I would not recommend using stubs in this way, but I decided
it was a shame that an exception was raised unnecessarily.

Note also that any expectations set on the original instance of Mock
will not be satisfied by invoking method on the re-hydrated instance of
Mock, because the two instances are completely different. This might be
solved by de-registering the Mock object when an instance with the same
"identitifer" is registered, but then I start wondering whether the
whole thing is a silly idea and we'd be better off raising an exception
if anyone attempts to serialize an instance of Mock.