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

Support for Spock #37

Closed
phejl opened this issue Mar 5, 2021 · 10 comments
Closed

Support for Spock #37

phejl opened this issue Mar 5, 2021 · 10 comments

Comments

@phejl
Copy link
Contributor

phejl commented Mar 5, 2021

It would be great to have a support for Spock. So one could use the library like this:

import dev.morling.jfrunit.*
import spock.lang.Specification

import java.time.Duration

import static dev.morling.jfrunit.JfrEventsAssert.*
import static dev.morling.jfrunit.ExpectedEvent.*

@JfrEventTest
class JfrSpec extends Specification {

    JfrEvents jfrEvents = new JfrEvents()

    @EnableEvent('jdk.GarbageCollection')
    @EnableEvent('jdk.ThreadSleep')
    def 'should Have GC And Sleep Events'() throws Exception {
        when:
        System.gc()
        sleep(1000)

        then:
        assertThat(jfrEvents).contains(event('jdk.GarbageCollection'))
        assertThat(jfrEvents).contains(
                event('jdk.ThreadSleep').with('time', Duration.ofSeconds(1)))
    }
}
@aalmiray
Copy link
Contributor

aalmiray commented Mar 5, 2021

AFAICT Spock 2.0 supports Junit Platform's Vintage and Jupiter engines which would allow Junit5 extension to be seamlessly consumed. Adding @leonard84

@gunnarmorling
Copy link
Member

Interesting idea, I certainly could see us doing that. What's the language used above, Groovy?

@aalmiray
Copy link
Contributor

aalmiray commented Mar 5, 2021

That is indeed Groovy.

@leonard84
Copy link
Contributor

leonard84 commented Mar 5, 2021

Spock 2.0 doesn't support junit-jupiter extensions (the jupiter API is far to complex for an easy support), although there is still best-effort support for junit4 rules.

The best thing would be to write a native Spock extension.
FYI, you can write Spock extensions in Java.

@gunnarmorling
Copy link
Member

gunnarmorling commented Mar 5, 2021 via email

@leonard84
Copy link
Contributor

I like that apparently this would provide a way to avoid the need for the explicit awaitEvents() call between the given/when and then.

This might not be possible to achieve via extensions at the moment, as spock doesn't expose those blocks at runtime to extensions. There is an open issue spockframework/spock#538 that touches on this.

@phejl
Copy link
Contributor Author

phejl commented Mar 5, 2021

I think I might have a PR soon :)

@phejl
Copy link
Contributor Author

phejl commented Mar 5, 2021

#38

@phejl
Copy link
Contributor Author

phejl commented Jul 29, 2021

@gunnarmorling I guess this can be closed now.

@gunnarmorling
Copy link
Member

Indeed, thx!

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

No branches or pull requests

4 participants