I thought I had a handle on the whole singleton class thing but now I’m
not too sure.
I have a class definition:
# complex and time consuming validation
# returns true on success, raises Exception
# on failure
Okay, so when I’m running my functional tests within rails, I want to be
able to control how the validate(params) method behaves.
So, I’ve created a ValidationMaster class definition and put it in
The methods I’ve defined there seem to be correctly overriding those of
the original class definition.
Now here is where I’m having problems. Within certain functional tests,
I want validate(params) to return true. Other times
I want it to fail and throw an exception. Thus, I can’t rely on the
Mock ValidationMaster class definition to take care of this.
But then I thought, HEY, within each test I can open up the singleton
class for the ValidationMaster class object. Whoo hoo,
I’m in charge now!
class << ValidationMaster
vm = ValidationMaster.new
But, when I run my test, the exception is not getting thrown. The
methods I’ve defined in the Mock are all working right, but it’s somehow
the override within test_stuff. Am I mistaken here, can I not override
the class definition of ValidationMaster like this?