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

Feature request: spying on concrete objects #77

Closed
jdpopkin opened this issue Apr 7, 2015 · 6 comments
Closed

Feature request: spying on concrete objects #77

jdpopkin opened this issue Apr 7, 2015 · 6 comments

Comments

@jdpopkin
Copy link
Contributor

jdpopkin commented Apr 7, 2015

I would like to be able to create a Spy using a concrete object rather than a constructor and list of constructor arguments. (I need this in order to set up private fields via introspection.)

I know this is a weird use case, but I'm not the only one interested in this. Would it be possible for a feature like this to be added in the future?

@cdeszaq
Copy link

cdeszaq commented May 28, 2015

👍

@twicksell
Copy link
Contributor

+1

leonard84 pushed a commit that referenced this issue Mar 22, 2017
* Add support for spying on concrete objects #77
* added spock:wrapWithSpy element to support replacement of a bean with a Spock spy
@Vampire
Copy link
Member

Vampire commented Sep 17, 2019

This is available since 1.1-rc-4 and can be closed

@ghost
Copy link

ghost commented Feb 19, 2020

Hi guys @Vampire, @leonard84, @twicksell

I know this is an ooooold ticket, but I just noticed that the implementation for Spies on concrete instances does not include the +Closure version of SpyImpl in SpecInternals.java.

This means I cannot provide interactions to the Spy, which is usually the purpose of creating them.

@Vampire
Copy link
Member

Vampire commented Feb 20, 2020

  1. Please do not ping random people
  2. That there is no closure variant of the factory method does not mean this feature is not implemented and is actually reported by me at Spy(T obj, Closure interactions) method is missing #1028
  3. Of course you can provide interactions, just not in such a closure block. You can do it in your feature method, you can do it in a setup method, you can do it with other Groovy means like Spy(foo).tap { 1* _ } or Spy(foo).with(true) { 1 * _ } there are many ways, just not the closure one which is a bit unnice and inconsistent to the others which is why I opened an issue for it, but they are still fully functional.

@leonard84
Copy link
Member

As there is a separate issue #1028 I'm closing this one.

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

No branches or pull requests

5 participants