Spock: Support for Groovy 3.0.0-beta-1

Created on 13 May 2019  路  38Comments  路  Source: spockframework/spock

Most helpful comment

@msgilligan We've been using the snapshot release with Groovy 3.x since May without any issues.

All 38 comments

You can test it with a snapshot build of 1.3 from https://oss.sonatype.org/content/repositories/snapshots/org/spockframework/spock-core/ and report your findings. In the Snapshots the version check is disabled.

Thanks!

@leonard84 The latest snapshot seems to work well with our builds, except for the minor codenarc issue that I linked here. Would it be possible to release a version without the version check?

FYI, Groovy 3.0.0-beta-3 will be released soon:
http://groovy.329449.n5.nabble.com/VOTE-Release-Apache-Groovy-3-0-0-beta-3-tt5760253.html

P.S. Groovy 3.0.0-beta-3 is probably the last beta version ;-)

Any updates on Groovy 3 support?

FYI. Groovy 3.0.0-rc-1 is released and Groovy 3.0.0-rc-2 will be released soon.

For me it's not Groovy without Spock. The way I want to start playing with Groovy 3 is via Spock tests, so without Spock I'm hesitant to try Groovy 3. I'm willing to try out early/snapshot versions on a branch of one of my projects, but at this point I don't see any documented way to do that.

@msgilligan We've been using the snapshot release with Groovy 3.x since May without any issues.

@henrik242 What maven coordinates should I use?

@msgilligan We've been using the snapshot release with Groovy 3.x since May without any issues.

could you show how you did it?

Just add https://oss.sonatype.org/content/repositories/snapshots/ to your maven repositories and depend on the snapshot release:

testImplementation('org.spockframework:spock-core:1.3-groovy-2.5-SNAPSHOT') {
    exclude group: 'org.codehaus.groovy'
}

@henrik242 Thanks. I was thinking it was the Spock 2.0 snapshot I should be using and wanted to make sure. I'll give it a try. It might be a good idea to make this information more readily/obviously available to potential early testers...

@msgilligan The 2.0 snapshot might work as well, just try it out :)

The 2.0 snapshot might work as well

I'm interested in the quickest path to a Groovy 3 migration of my project. Which branch do you think will see a stable release that supports Groovy 3 first?

Just try whichever you want, it's easily done. 1.3 has been stable for me since May.

Just try whichever you want, it's easily done. 1.3 has been stable for me since May.

Oh, sorry. I did try 1.3 snapshot out -- and it works: https://github.com/ConsensusJ/consensusj/pull/56

When will there be a new release of the 1.3 branch? Would that be 1.3.1?

I doubt there will be a 1.3.1 release now that the 2.0 stuff got merged to master which is what you refer to as "1.3 branch".

@henrik242

@msgilligan We've been using the snapshot release with Groovy 3.x since May without any issues.

I was doing some experiments,
and I had a problem mocking a simple getter.

Githup repo with de code

Controller.groovy

  @GetMapping(path = '/pessoa/{id}', produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
  PessoaDto getPessoa(@PathVariable int id) {
    LOGGER.debug('Id passado' + id)
    pessoaService.pessoa
  }

Service.groovy

@Service
class PessoaService {
  private final String name  = 'teste'
  PessoaDto getPessoa() {
    new PessoaDto(this.name)
  }
}

TestController.groovy

        1 * this.pessoaService.getPessoa() >> {
            new PessoaDto("bruno001")
        }

This mock does not work, see erro below:

Too few invocations for:

1 * this.pessoaService.getPessoa() >> {
            new PessoaDto("bruno001")
        }   (0 invocations)

Unmatched invocations (ordered by similarity):

1 * <PessoaService>.getProperty('pessoa')
methodName == "getPessoa"
|          |
|          false
|          7 differences (36% similarity)
|          getP(rop)e(rty-)
|          getP(---)e(ssoa)
getProperty

If a change the mock to:

TestController.groovy

        1 * this.pessoaService.pessoa >> {
            new PessoaDto("bruno001")
        }

I get a different erro:

Too few invocations for:

1 * this.pessoaService.pessoa >> {
            new PessoaDto("bruno001")
        }   (0 invocations)

Unmatched invocations (ordered by similarity):

1 * <PessoaService>.getProperty('pessoa')
propertyName == "pessoa"
|            |
null         false

I ask:
You have this problem? If yes I will open a issue.

I doubt there will be a 1.3.1 release now that the 2.0 stuff got merged to master which is what you refer to as "1.3 branch".

This comment https://github.com/spockframework/spock/issues/1049#issuecomment-572624893 says that Spock 2.0 _won't_ support Groovy 3.0 in its first release. If that's true and the 1.3 branch "works" with Groovy 3.0 will there be a 1.3.1 release?

No it does not.
It says "not necessarily".
But Groovy 3.0.0 was just released and the quirks in Spock for supporting it ironed out.
Groovy 3 support was just merged into master and thus will be part of the next milestone release.

No it does not.
It says "not necessarily".

Sorry, my brain read "not necessarily" as "we're not going to do any work to support Groovy 3.0 for this first Spock 2 release".

But Groovy 3.0.0 was just released and the quirks in Spock for supporting it ironed out.
Groovy 3 support was just merged into master and thus will be part of the next milestone release.

This is great news! Thanks!

And version 2.0-M2-groovy-3.0 was released today. Great work! Thank you!

It turned out to be possible (and feasible) to cover both Groovy 2 and 3 support in one codebase. Closing - 2.0-M2-groovy-3.0 is released.

Btw, guys, please write comments here if you successfully migrated your projects to Spock 1.2-M2 and Groovy 3 (or create separate issues if you encountered any related problem).

Hello, I'm a bit confused by all this: I don't quite understand, is there a Groovy 3 version of Spock 1.3 available? I've ended up here after looking at the various artifacts Maven Central appears to be offering...

If so, how do I include it in my build.gradle? When asked for the "coordinates" of the dependency, henrik242 says

"Just add https://oss.sonatype.org/content/repositories/snapshots/ to your maven repositories and depend on the snapshot release:
testImplementation('org.spockframework:spock-core:1.3-groovy-2.5-SNAPSHOT') {
exclude group: 'org.codehaus.groovy'
}"

Questions:
1) what does that mean, "add X to your maven repositories" ?
2) that appears to be a Groovy2.5 snapshot for Spock 1.3... when I thought this was all about a Groovy3 version of Spock 1.3?
3) could someone explain why that "exclude group" line is there?

That answer was given on 2019-11-03. Is it in fact possible to get a Groovy3 version of Spock 1.3? Or am I in fact obliged to switch to Spock2?

Sorry for the confusion and low level of my understanding.

@Mrodent no, there is no Groovy 3 support for 1.x. The reason the snapshots were mentioned is that the version checks are disabled in those. However, you need to use Spock with version 2.0-M2-groovy-3.0 for Groovy 3 support.

However, you need to use Spock with version 2.0-M2-groovy-3.0 for Groovy 3 support.

That's not quite correct. We've used 1.3-groovy-2.5-SNAPSHOT without issues since May last year, with only Groovy 3.x on the classpath.

@Mrodent

1) Here's how you add a maven repository to your Gradle config: https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:declaring_multiple_repositories
2) It's built with 2.5, but works with 3.x too
3) It excludes transitive dependencies to Groovy 2.x, since we're adding the Groovy 3.x dependencies manually

Spock 1.3 may work with Groovy 3.x accidentally (they most likely are corner cases where is doesn't). Spock 2.0-M2+ provides official support for Groovy 3.x, so it is tested with it and we will try to fix spotted problems.

Update. Snapshots "may work", the release version had implemented Groovy version checking and should mail with meaningful error message. Mostly probably to limit number of bug reports related to unsupported Groovy version.

Btw, for people willing to migrate to Groovy 3 mostly for Java 14+ support, the good news is that Groovy 2.5.10 fixed GROOVY-9211 which was the main problem.

Our main repo has more than 800 test classes using Spock. We've had surprisingly little (if any) problems using 1.3-groovy-2.5-SNAPSHOT with Groovy 3.

@henrik242 Great to here. I wonder, if you had many problems playing with Spock 2.0 (if you have it a try)?

@szpak I've been trying the 2.0 branch on and off during the last months, but there are some tests that fail that I haven't been able to fix yet. I'll get back to you when I figure it out (or if I manage to create a small reproducible test project)

Thanks for clarifying this.

Hi folks, wondering if you have faced the following:

Given this buildscript

plugins {
    id 'groovy'
    id 'java-library'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.2'
    testImplementation('org.spockframework:spock-core:2.0-M2-groovy-3.0') {
        exclude group: 'org.codehaus.groovy'
    }
}

Running the test task, results in no tests executed. However, I can see the compiled classes under build/classes

Here is a sample repo in case you want to take a look: https://github.com/nebula-plugins/gradle-nebula-integration/tree/master/groovy3-issue

But it is a simple groovy spec with one single method

Wondering if I'm missing something in order to use spock with groovy.

never mind, found that I missed

test {
    useJUnitPlatform()
}

Yes, it's a limitation of Gradle to do not fail when there are not tests (which it would be good to have it by default - to make an alarm).

A possible workaround that I described in my blog about the migration:
https://blog.solidsoft.pl/2020/01/02/migrating-spock-1.3-tests-to-spock-2.0/#gradle

test {
    useJUnitPlatform()

    afterSuite { desc, result ->
        if (!desc.parent) {
            if (result.testCount == 0) {
                throw new IllegalStateException("No tests were found. Failing the build")
            }
        }
    }
}

To get know that you screwed up your configuration ;-).

@szpak Here's an example of something that doesn't work yet: https://github.com/spockframework/spock/issues/1073#issuecomment-617009915

Was this page helpful?
0 / 5 - 0 ratings