grails/grails-core — pull request #274 by sjurgemeyer (2012-10-23 01:44:19+00:00)
Title: GrailsMock.demand does not recognize if a method doesn't exist

GrailsMock.demand does not check to see if the method signature exists on the mocked out class. This is understandable, since dynamic methods can be added at anytime. It can be frustrating when refactoring though. You can change a method signature and see tests passing, only to later find out that you missed a test with a mocked out version of the method.

This pull request adds a 'demandExplicit' method to GrailsMock which checks the existing methods for a class before creating the mock object. If it does not exist, an exception is thrown, otherwise it operates exactly like the current demand method.

I think this is a good solution as it allows the developer to decide if they want to use the more strict mocking and does not affect existing tests.