Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot declare multiple variables in single line inside setup block #531

Open
jordi-chacon opened this issue Sep 24, 2015 · 3 comments
Open
Labels

Comments

@jordi-chacon
Copy link

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

@snimavat
Copy link

This is a real issue, and doesnt work for me either.

Guyz please fix it, spock shoulnt be breaking groovy syntax.

@leonard84 leonard84 added the bug label Oct 23, 2015
@leonard84
Copy link
Member

related #495

@ssirovy
Copy link

ssirovy commented Apr 6, 2016

I've found that inserting a single variable declaration immediately after the setup: or when: labels will get around this issue. In other words, the error seems to manifest when non-initialized multiple variable declarations immediately follow the setup: or when: blocks.

This works as expected:

def "foo"() {
  when:
  def aSingleVar         // when this is present, the next line is allowed
  def a, b
  a = 0
  b = 1

  then:
  a != b
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants