Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mlasevich opened this issue Oct 20, 2023 · 0 comments
Labels

Comments

@mlasevich
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant