spockframework / spockframework/spock

Spock assertion inside if-statement doesn't work

Open
#1,160 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

See this blog post for a thorough analysis of the issue.

Given test case:

def "should fail on expected == result comparison"() {
    given:
    def expected = "Hello, John!"

    when:
    def result = "Hello, Joe!"

    then:
    if (expected) {
        expected == result
    }
}

Expected result: FAIL
Actual result: PASS

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 by reproducing the provided Groovy specification with the conditional assertion, then trace Spock's handling of assertions inside if-statements. Done means the example fails when expected and result differ, with a regression test covering the conditional case.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.