Refactored MockFunction to register the before(:each) hook in a better context