Flexible Mock
Hey, I've been posting too many abstract shit lately, how about some code? So here's my simple Mock class and tests for it (to show how it works). Class class Mock def initialize(method_name, block = nil ) block||=Proc.new do |*args| args=args.first if args.length==1 yield(args) end self.class.send :define_method, method_name, block end end Examples class TestMock The problem with other mock libraries is that there's too much magic going on and syntax is tricky mock.expect :method, 'return', [:params] ... mock.verify # or mock.should_receive(:method).with("A", 1, 3).once In more complex examples it gets hard to express what you want and remember syntax. I prefer more control, that's why my decision is to create object with custom method. In this method you can do whatever you want. Another good thing of this approach is property of Proc to maintain context where it was called (look at...