spockframework / spockframework/spock

Using GroovySpy on class with propertyMissing() results in unexpected MissingMethodException

Open
#1,815 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

when using GroovySpy() with an obkject that has propertyMissing() implemented, attempts to access dynamic properties results in an exception

To Reproduce
package example

import spock.lang.Specification

class TestClass {

  def propertyMissing(String name) {
    return name
  }
}

class TesterSpec extends Specification {

  def 'No Spy'() {
    given: 'an instance'
      TestClass sut = new TestClass()

    expect: 'property to be returned'
      sut.bob == 'bob'
  }

  // This does not work
  def 'Spy'() {
    given: 'a spied instance'
      TestClass sut = GroovySpy()

    expect: 'property to be returned'
      sut.bob == 'bob'
  }
}

Expected behavior

Both test should pass

Actual behavior

second test fails with

ondition failed with Exception:

sut.bob == 'bob'
|   |
|   groovy.lang.MissingMethodException: No signature of method: example.TestClass.getBob() is applicable for argument types: () values: []
|   Possible solutions: getAt(java.lang.String), getClass(), notify(), every(), grep()
|   	at example.TesterSpec.Spy(TesterSpec.groovy:27)
example.TestClass$$EnhancerByCGLIB$$9a1d9323@7e0f56d8
Java version

Corretto-11

Buildtool version
------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------

Build time:   2020-10-14 16:13:12 UTC
Revision:     312ba9e0f4f8a02d01854d1ed743b79ed996dfd3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.14.1 (Amazon.com Inc. 11.0.14.1+10-LTS)
OS:           Mac OS X 13.6 x86_64
What operating system are you using

Mac

Dependencies

Using Spock 1.3-groovy-2.4 with Groovy 2.4.12

Additional context

This is in a very specific setup, so on old version of spock/Groovy but I am told it is recreatable with latest version

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 running the provided TesterSpec and compare the passing “No Spy” example with the failing “Spy” example. Trace GroovySpy handling of the dynamic property access and propertyMissing(String name), using the reported MissingMethodException as the failure point. Done means both examples pass without the exception on a supported Spock/Groovy setup.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.