Dynamic languages should be very easy to test. Instead of dealing with mock objects or stub classes, you should just be able to dynamically override the methods of an object instance. I finally figured out how to do this in ruby.
Assume the Event class has a method, send_email, you'd like to override for testing.
event = Event::new("something happened")
def event.send_email()
email_sent
@test = true
end
def event.test()
return @test
end
event.run_action()
assert event.test
This redefines the send_email method for our instance of the Event class with a stub method that sets an attribute. Note that this redefinition is not a closure (it doesn't know about variables of the surrounding scope), so the only way to confirm it was called is to set an instance variable. Since our test needs to read this instance variable, we also have to define an accessor for it. If anyone out there knows a better way to confirm the stub method is called, I'd like to see it.
Also, note that this is only good for a single instance. If you'd like to be able to quickly apply this kind of modification on demand, the appropriate way is to define a module, and use the Object::extend method.