Export to GitHub

spock - issue #320

Injecting a TestRule into a spock specification


Posted on Jul 10, 2013 by Swift Kangaroo

I'm trying to inject a rule which is configured in a spring context into a spock specification.

@ContextConfiguration(locations=["spring.xml"]) class TestSpec extends Specification { @Rule @Inject //@Autowired public ActivitiRule activitiRule;

@Deployment
def "Process test"() {
when:
//...
then:
//...
}

}

The problem is that spock instantiates the rule by itself without respecting the @Inject or @Autowired annotation.

>Interesting use case. The problem is that Spock's Rule extension invokes the rule before Spock's Spring extension injects it. It may be possible to fix this. If you don't mind, please submit an issue at http://issues.spockframework.org. For now, only injection of MethodRules (as opposed to TestRules) will work as expected.

http://stackoverflow.com/questions/17545264/injecting-a-rule-into-a-spock-specification

Comment #1

Posted on Jul 10, 2013 by Grumpy Cat

The problem is that spock instantiates the rule by itself without respecting the @Inject or @Autowired annotation.

That's not the problem. Anyway, thanks for reporting the issue.

Comment #2

Posted on Mar 1, 2015 by Grumpy Cat

(No comment was entered for this change.)

Status: Accepted

Labels:
Type-Defect Module-Core Milestone-1.1