|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value={TYPE,METHOD}) public @interface 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.
Required Element Summary | |
---|---|
Class[] |
value
|
Element Detail |
---|
public abstract Class[] value
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |