Document AssertJ interoperability with Spock 2.4 and Groovy

Open
#167 15 comments 3 reactions 1 assignee View on GitHub

@scordio is already working on this.

Since Mar 1, 2024.

Assessment

This issue has not been assessed yet.

Description

Describe the bug
The feature from assertj/assertj#2520 seems to be incompatible with using the StringAssertfrom assertj-core in a Groovy and Spock setup.

The then block in a spock test feature wraps any assertion code line with an groovy powerassert assert under the hood expecting the actual assertion expression to be evaluated as a boolean value. In Groovy there is the org.codehaus.groovy.runtime.DefaultGroovyMethods#asBoolean(java.lang.Object) method that Spock is calling. Due to the changes made to the AbstractStringAssert class this method is inaccessible and returns a BooleanAssert instead.

  • assertj core version: 3.25.3
  • java version: 17
  • groovy version: 4.0.18
  • test framework version: Spock 2.3-groovy-4.0
  • os (if relevant):

Test case reproducing the bug

Add a test case showing the bug that we can run

import spock.lang.Specification

import static org.assertj.core.api.Assertions.assertThat

class DemoSpec extends Specification {
    def 'assert some integer'() {
        when:
        def someInteger = 10

        then:
        assertThat(someInteger).isEqualTo(10)
    }

    def 'assert some string'() {
        when:
        def someString = 'some string'

        then:
        assertThat(someString).isEqualTo('some string')
    }
}
Dominant language
CSS
Stars
26
Forks
32
Avg merge
1d 19h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

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.

More from assertj/doc

All issues in assertj/doc

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.