From: jeem Date: 2005-03-15T23:01:34+09:00 Subject: Re: Mocking new and other class methods Sorry, I'll try to clarify. When I type this: mn=MockNew.new(A) mn.handle { block } I'm saying, "Next time someone calls A.new(args), execute this block instead." This lets me test code like this: def methodToTest etc a = A.new('bob') a.etc end Usually I want to find some other way to test code like this, but if A.new or a.etc hits the file system or network, etc., I really want to be able to sub in a mock. Often we deal with this by passing in the object, thus isolating the object creation code. This still leaves the creation code untested, and a good place for bugs to hide.