jtanistra / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Injecting a TestRule into a spock specification #320

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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-specif
ication

Original issue reported on code.google.com by l.brueni...@googlemail.com on 10 Jul 2013 at 5:45

GoogleCodeExporter commented 8 years ago
> 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.

Original comment by pnied...@gmail.com on 10 Jul 2013 at 5:52

GoogleCodeExporter commented 8 years ago

Original comment by pnied...@gmail.com on 1 Mar 2015 at 11:45