Grails / Spock how to test if a specific contraints fails?
Question
Is there an easy way of identifying if a specific contraint in a spock test has failed?
I now more or less check if there the domain hasErrors according to the example on the wiki. http://code.google.com/p/grails-spock-examples/wiki/Overview#Testing_constraints
But i would like to find out if a specific validation constraint failed to make sure that later on no other constraints are failing.
Solution
The domain object will have a list of errors within it, using the first example from the link you posted it would be:
author.errors.first()
to get the first error. You can always use the groovy find method to find the particular error you are looking for.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow