spockframework / spockframework/spock

GroovySpy and Traits

Open
#99 1 comment 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

According to the latest Groovy 2.4 documentation (http://www.groovy-lang.org/objectorientation.html#_duck_typing_and_traits), traits support Duck Typing. So, if I were to create a trait and add it to a class that extends Specification, I should be able to call GroovySpy. Unfortunately, when I do this, Spock complains that Mocks/Spies can only be created in a specification. I'm guess that Spock does some extra checks and the call made by the trait does not pass.

It would be really nice if traits were more fully supported. It would allow me to reuse code in my tests. I could do this with a base class, but that restricts me to single inheritance. Traits are more flexible and allow for composition.

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 Groovy 2.4 trait example with a trait mixed into a Specification and calling GroovySpy, then trace the specification check that rejects the call. Done means a trait-provided GroovySpy call is accepted for a Specification while calls from non-specifications still produce the existing error.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
testing
Issue type
Feature
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.