spockframework / spockframework/spock

Cannot declare multiple variables in single line inside setup block

Open
#531 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Hi,

I can't seem to define, without initializing, multiple variables in one line inside a when or a setup block.

Example:

import spock.lang.Specification

class exampleSpec extends Specification {

  def "foo"() {
    when:
    def a, b
    a = 0
    b = 1

    then:
    a != b
  }
}

This fails when accessing b:
No such property: b for class: ....

Moving the declaration outside the block works.

I am using:

Groovy Version: 2.4.3 JVM: 1.8.0_45 Vendor: Oracle Corporation OS: Linux

http://stackoverflow.com/questions/32763054/declare-multiple-variables-in-one-line-in-spock-when-block/32765082#32765082

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 provided Spock specification and compare multiple-variable declarations inside the when and setup blocks with declarations outside those blocks. Investigate how Spock handles block-local variables, using the reported No such property: b failure as the expected behavior to reproduce; done means the example can access both variables and the regression is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.