Hi,
This is the domain class:
class Registration {
String email
String generatedKey
def beforeInsert = {
String newToken = GlobalHelper.getRandomString()
generatedKey = newToken
}
}
and this is the relevant part of the unit test:
def c = mockFor(GlobalHelper)
c.demand.static.getRandomString {-> return "nestoABC" }
c.createMock()
reg.beforeInsert()
When running the test, I get this error:
No such property: GlobalHelper for class: RegistrationTests
groovy.lang.MissingPropertyException: No such property: GlobalHelper for class: RegistrationTests at RegistrationTests.testConstraints(RegistrationTests.groovy:57)
The GlobalHelper class is located in Groovy source folder, and the mentioned line 57 is the line with the mockFor() method.
Grails Testing docs were not very helpfull regarding this issue...
I know this would be easily solved using integration tests, but I think it should also work this way.
Thanks in advance