Closed GoogleCodeExporter closed 8 years ago
Unfortunately that's not how JUnit rules work, and we have to comply with their
semantics. But you can always write a Spock extension to achieve that.
In JUnit 4.9 they've introduced two new kinds of rules (MethodRule and
ClassRule) and Spock 0.6 will support them both. Not sure if it solves your
problem but maybe it does (I know it was a frequent complaint).
Original comment by pnied...@gmail.com
on 30 Sep 2011 at 1:31
What if we had a special annotation that changed the semantics to do what I am
talking about? So you could use MethodRule impls, but change their lifecycle.
Original comment by luke.da...@gradle.biz
on 30 Sep 2011 at 1:34
I think it's better to add support for JUnit 4.9's TestRule, which will solve
your problem. A TestRule annotated with @Rule will run "around" setup() and
cleanup(). If annotated with @ClassRule, it will run "around" setupSpec() and
cleanupSpec(). TestRule replaces MethodRule, which has been deprecated.
Alternatively, you can always write a Spock extension.
Original comment by pnied...@gmail.com
on 3 Oct 2011 at 1:15
Supporting TestRule sounds good. In this case it's one of the rules we use in
Gradle so an extension would be more work.
Original comment by lda...@gmail.com
on 3 Oct 2011 at 9:00
Original comment by lda...@gmail.com
on 3 Oct 2011 at 9:01
Original comment by pnied...@gmail.com
on 4 Oct 2011 at 8:00
There is now full support for TestRule, including @ClassRule. The only
limitation is that test failures will be reported even if a TestRule suppresses
them. This is because Spock and JUnit report failures at different times. Maybe
this can be reconciled, but I’m not sure.
Original comment by pnied...@gmail.com
on 19 Jan 2012 at 2:43
Original issue reported on code.google.com by
luke.da...@gradle.biz
on 30 Sep 2011 at 1:01