prayagupadhyay
prayagupadhyay

Reputation: 31232

Working with GrailsUnitTestCase and Spock Specification in the same project

I have existing UnitTests written extending grails' GrailsUnitTestCase. I wrote new Unit Tests using Spock framework. Running individual Spock Spec with following command is fine.

prayag@prayag:~/gccount$ grails test-app spock: ChronicSpec

But running existing UnitTests throws compilation error in Spock Tests.

prayag@prayag:~/gccount$ grails test-app unit: ChronicUnitTest.testDefaultChronic

| Error Compilation error compiling [unit] tests: startup failed:
/home/prayag/gccount/test/unit/com/zazzercode/chronic/ChronicSpec.groovy: 45: unexpected token: } @ line 45, column 5.
       } //end of response process
       ^

1 error

ChronicSpec.groovy is as below

class ChronicSpec extends Specification {

    final public String CHRONIC_DEFAULT_METRIC  = ReportType.CHRONIC_REPORT + Constants.COLON + ChronicMetrics.DEFAULT
    final public String INDEX_NAME = "gccount"

    ChronicService chronicService

    void "when response is processed json should be created"() {

        given:
            def contentBuilder = XContentFactory.jsonBuilder().startObject()
            chronicService = new ChronicService()
            //other code goes here

        when:
            listener.writeJson(records, contentBuilder, "chronic")
        then:
            //assertion goes here
    } //end of response process => this is where exception is thrown
}

Tools 'm using

grails : 2.2.3

spock : 0.7

Upvotes: 1

Views: 545

Answers (1)

Calahad
Calahad

Reputation: 1488

I am surprised this actually compiles, you cannot leave an empty "then:" block.

You need at least one assertion. As suggested by Sergio Michels, add an assertion and it should fix it.

Upvotes: 1

Related Questions