spockframework / spockframework/spock

Shorter way to define expected exception class together with message

Open
#146 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-Enhancement
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 23

This snippet works ok:

then:
def e = thrown(HostException)
e.message == "No active testcase"

while following doesn't catch the exception:

then:
thrown(HostException).message == "No active testcase"

It could be good to support such shortcut definition.

Reported by irium.now on 2009-04-22 17:53:02

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 then: snippets and the existing thrown(HostException) expression to trace how exception conditions are evaluated. The work is done when the shorter expression also checks the exception message and preserves the existing behavior for the separate variable-and-comparison form.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.