I have a Spock integration test that looks something like this:
class PriceTierControllerIntegrationSpec extends IntegrationSpec {
PriceTierController controller
def setup() {
controller = new PriceTierController()
}
def "applyDiscount() method will redirect user to success view"() {
when:
controller.applyDiscount()
then:
controller.response.redirectedUrl == '/priceTier/success'
}
Then in the controller, the logic is simply:
class PriceTierController {
def applyDiscount() {
redirect action: 'success'
}
def success() {
}
}
When I run this Spock test on my local machine, the test passes. However, on the build server, I get the following error:
controller.response.redirectedUrl == '/priceTier/success'
| | | |
| | /test/success false
| | 8 differences (46% similarity)
| | /(t---)e(st--)/success
| | /(pric)e(Tier)/success
| org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletResponse@dc42543
com.test.PriceTierController@193d6547
For some reason, on the build server, the Spock test thinks that the controller name is test
instead of priceTier
, and the test will fail. This only seems to happen for Spock integration tests, as the Spock unit tests and a few legacy Grails mixin tests all pass fine.
Does anybody know what could be causing this problem?
I've also just experienced this same issue, and it seems that it comes down to the test framework extracting the controller name from the the name of the testing class.
The convention is that the test class is named
<controller name>ControllerSpec
In the above case, the test class should be named
PriceTierControllerSpec
so that the test framework will successfully resolve the controller toPriceTeir
.Naming the class according to these guidelines seems to fix this problem.
Further reference can be found here: https://jira.grails.org/browse/GRAILS-10962