hakandilek / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

where block is being run before the setup() method, causing NullPointerException #317

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem? If possible, provide source code and
stack trace.
1. Run the attached spec using Grails. Entity class can be any Domain Class 
with a property named 'code'.
2. If you run it as it is, it fails
3. If you comment the where block and uncomment the '// This works:' part, it 
works

This is very odd. In my opinion, it shouldn't matter whether you put the 
assignment part (the one which fails) in the where block or in the expect or 
when blocks.

What version of Spock and Groovy are you using?
Spock 0.7
Grails 2.2.2
Groovy 1.8.6

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

Stacktrace:

| Running 1 spock test... 1 of 1
| Failure:  issue(orcamento.IssueSpec)
|  java.lang.NullPointerException: Cannot get property 'id' on null object
    at IssueSpec.issue(IssueSpec.groovy:28) <---------- The line of 'instanceId = instance.id', inside the where block
| Completed 1 spock test, 1 failed in 35ms
| Tests FAILED  - view reports in 
/home/andre/desenvolvimento/projetos/administracao/orcamento/target/test-reports

Original issue reported on code.google.com by awvale...@gmail.com on 18 Jun 2013 at 12:35

Attachments:

GoogleCodeExporter commented 9 years ago
Works as designed. `where` does (and has to) run before `setup`.  The latter is 
run once per `iteration`, whereas `where` is run once per method. This topic 
has been discussed often before, and there isn't a known way to improve on the 
current model.

Original comment by pnied...@gmail.com on 18 Jun 2013 at 5:36