Package spock.util.mop
Annotation Type Use
Activates one or more Groovy categories while the annotated spec method
or class executes. In other words, @Use(SomeCategory)
has the same effect as wrapping the execution of the annotated method or
class with use(SomeCategory) { ... }.
Basic example:
class ListExtensions { static avg(List list) { list.sum() / list.size() } } class MySpec extends Specification { @Use(ListExtensions) def "can use avg() method"() { expect: [1, 2, 3].avg() == 2 } }
One use case for this feature is the stubbing of dynamic methods which are usually provided by the runtime environment (e.g. Grails).
Note: @Use has no effect when applied to a helper method. However, when applied to a spec class it will also affect its helper methods.
- Author:
- Peter Niederwieser
-
Required Element Summary
Required Elements
-
Element Details
-
value
Class[] value
-