spockframework / spockframework/spock

Incompatible mockDomain Return Type

Open
#316 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-Defect
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 194

What steps will reproduce the problem? If possible, provide source code and
stack trace.
1. Create a unit test for testing constraints (see code below)
2. grails test-app :spock

| Error Compilation error compiling [spock] tests: startup failed:
/home/erturne/myapp/test/unit/foo/UserTests.groovy: -1: The return
type of java.lang.Object mockDomain(java.lang.Class, java.util.List)
in foo.UserTests is incompatible with void mockDomain(java.lang.Class,
java.util.List) in grails.plugin.spock.UnitSpec
. At [-1:-1]  @ line -1, column -1.

package foo

import grails.plugin.spock.*
import grails.test.mixin.*

/**
 * See the API for {@link
grails.test.mixin.domain.DomainUnitTestMixin} for usage instructions
 */
@TestFor(User)
class UserTests extends UnitSpec {

       def "first name must not violate constraints"() {
               setup:
               mockForConstraintsTests(User)

               when:
               def user = new User(firstName: firstName, lastName: 'Doe')
               user.validate()

               then:
               user.hasErrors() == !valid

               where:
               firstName               | valid
               null                    | false   // Must not be null
               ''                      | false   // Must not be blank
               '012345678901234567891' | false   // Must not exceed 20 characters
               'John'                  | true    // Okay
       }
}


What version of Spock and Groovy are you using?
Groovy: 1.8
Grails: 2.0.0M1
Spock plugin: 0.6-SNAPSHOT


Please provide any additional information below. You can also assign
labels.

Reported by erturne on 2011-08-10 12:14:58

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing test in test/unit/foo/UserTests.groovy and reproduce it with grails test-app :spock. Trace the mockDomain method on grails.plugin.spock.UnitSpec and the generated UserTests method signature; done means the constraints test compiles without the incompatible return-type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.