spockframework / spockframework/spock

Improved assertion message in "with(object) {}"?

Open
#1,284 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Issue description

    def "should keep verbose error message"() {
        given:
            String foo = "foo message"
        expect:
            foo.contains("bar")
    }

results in very nice error message:

Condition not satisfied:

foo.contains("bar")
|   |
|   false
foo message

However, when with(object) {} is used with the same assertion:

    def "should keep verbose error message"() {
        given:
            String foo = "foo message"
        expect:
            with(foo) {
                contains("bar")
            }
    }

it looks worse:

Condition not satisfied:

contains("bar")
|
false

Maybe it would be possible in AST transformation to get the real object value and present it?

Additional Environment information

Spock 2.0-M4-groovy-3.0

Java/JDK

OpenJDK 15

Groovy version

3.0.7

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 two Groovy assertion examples in the issue and trace the AST transformation used by with(object) {}. Compare its failure output with the direct assertion, then verify that the transformed form preserves the relevant object value and produces a more verbose message.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
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.