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

Potential extension for assertions within Mock closures #1001

Open
mwhipple opened this issue May 30, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@mwhipple
Copy link

commented May 30, 2019

This is probably a better fit for the dev-forum but I can't seem to access it :(.

I threw together an extension awhile ago and one of my coworkers just asked if I looked into merging it upstream so I figured it was worth quickly gauging interest (it also seems fine to leave as an external extension).

https://gitlab.com/mwhipple/spock-thenclose-extension

The quick summary cribbed from the README is that it provides an extension ThenCleanup which allows definition of methods to be invoked at the end of a then: the primary use case of which is to add support into a Specification subclass to allow tests such as:

class MySpec extends ThenkfulSpecification {
    def 'some work should call some stuff'() {
        when:
        myCode.doWork('foo')

        then:
        1 * worker.doSomething(*_) >> { args ->
            thenk { assert args[0].content == 'foo' }
            thenk { assert args[0].id }

            myReturnValue
         }
     }
 }

where assertions can be defined within the Mock closure but are not evaluated until control is handed back to Spock. More info is in the README (though the extension piece hasn't been doc'ed). Let me know if there's interest and I could look towards making whatever adjustments are needed to make it PR-worthy.

@mwhipple mwhipple changed the title Potential extension contribution Potential extension for assertions within Mock closures May 30, 2019

@leonard84

This comment has been minimized.

Copy link
Member

commented May 31, 2019

Hi @mwhipple, have you looked at the new reporting features of Spock 1.3? In that version we improved unmatched invocation reporting a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.