{"action":"created","issue":{"url":"https://api.github.com/repos/spockframework/spock/issues/584","repository_url":"https://api.github.com/repos/spockframework/spock","labels_url":"https://api.github.com/repos/spockframework/spock/issues/584/labels{/name}","comments_url":"https://api.github.com/repos/spockframework/spock/issues/584/comments","events_url":"https://api.github.com/repos/spockframework/spock/issues/584/events","html_url":"https://github.com/spockframework/spock/issues/584","id":153736802,"number":584,"title":"JUnits MethodRule does not work as expected with Spock-1.0-groovy 2.4","user":{"login":"tschulte","id":203910,"avatar_url":"https://avatars.githubusercontent.com/u/203910?v=3","gravatar_id":"","url":"https://api.github.com/users/tschulte","html_url":"https://github.com/tschulte","followers_url":"https://api.github.com/users/tschulte/followers","following_url":"https://api.github.com/users/tschulte/following{/other_user}","gists_url":"https://api.github.com/users/tschulte/gists{/gist_id}","starred_url":"https://api.github.com/users/tschulte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschulte/subscriptions","organizations_url":"https://api.github.com/users/tschulte/orgs","repos_url":"https://api.github.com/users/tschulte/repos","events_url":"https://api.github.com/users/tschulte/events{/privacy}","received_events_url":"https://api.github.com/users/tschulte/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-09T09:30:08Z","updated_at":"2016-05-09T09:45:59Z","closed_at":null,"body":"I wanted to use Griffon's GriffonUnitRule with Spock. GriffonUnitRule implements MethodRule. I found the Rule's before method is called after the Spec's setup method. Therefore DependencyInjection performed by the Rule has not happened yet. Due to #328 this should work. But I found it does not. The following code shows the problem:\r\n\r\n```groovy\r\npackage spock.rules\r\n\r\nimport org.junit.*\r\n\r\nimport spock.lang.Specification\r\n\r\nclass SomeSpec extends Specification {\r\n\r\n    @Rule\r\n    public SomeMethodRule someMethodRule = new SomeMethodRule()\r\n\r\n    @Rule\r\n    public SomeTestRule someTestRule = new SomeTestRule()\r\n\r\n    def setup() {\r\n        System.err.println \"Spec: setup\"\r\n    }\r\n\r\n    def cleanup() {\r\n        System.err.println \"Spec: cleanup\"\r\n    }\r\n\r\n    def \"some spec\"() {\r\n        System.err.println \"Spec: expect\"\r\n        expect:\r\n        true\r\n    }\r\n}\r\n```\r\n\r\n```java\r\npackage spock.rules;\r\n\r\nimport org.junit.rules.TestRule;\r\nimport org.junit.runner.Description;\r\nimport org.junit.runners.model.Statement;\r\n\r\npublic class SomeTestRule implements TestRule {\r\n\r\n    @Override\r\n    public Statement apply(Statement base, Description description) {\r\n        final Object target = description;\r\n        return new Statement() {\r\n            @Override\r\n            public void evaluate() throws Throwable {\r\n                before(target);\r\n                try {\r\n                    base.evaluate();\r\n                } finally {\r\n                    after(target);\r\n                }\r\n            }\r\n        };\r\n    }\r\n\r\n    protected void before(Object target) {\r\n        System.err.println(\"TestRule: before\");\r\n    }\r\n\r\n    protected void after(Object target) {\r\n        System.err.println(\"TestRule: after\");\r\n    }\r\n}\r\n```\r\n\r\n```java\r\npackage spock.rules;\r\n\r\nimport org.junit.rules.MethodRule;\r\nimport org.junit.runners.model.FrameworkMethod;\r\nimport org.junit.runners.model.Statement;\r\n\r\npublic class SomeMethodRule implements MethodRule {\r\n\r\n    @Override\r\n    public Statement apply(Statement base, FrameworkMethod method, Object target) {\r\n        return new Statement() {\r\n            @Override\r\n            public void evaluate() throws Throwable {\r\n                before(target);\r\n                try {\r\n                    base.evaluate();\r\n                } finally {\r\n                    after(target);\r\n                }\r\n            }\r\n        };\r\n    }\r\n\r\n    protected void before(Object target) {\r\n        System.err.println(\"MethodRule: before\");\r\n    }\r\n\r\n    protected void after(Object target) {\r\n        System.err.println(\"MethodRule: after\");\r\n    }\r\n}\r\n```\r\n\r\nDoes result in the following output (tested with 0.7-groovy-2.0, 1.0-groovy-2.4 and 1.1-groovy-2.4-SNAPSHOT build from commit cffc725):\r\n\r\n```\r\n    TestRule: before\r\n    Spec: setup\r\n    MethodRule: before\r\n    Spec: expect\r\n    MethodRule: after\r\n    Spec: cleanup\r\n    TestRule: after\r\n```\r\n\r\nI would have expected, that `MethodRule: before` to be executed before `Spec: setup` and `MethodRule: after` to be executed after `Spec: cleanup`"},"comment":{"url":"https://api.github.com/repos/spockframework/spock/issues/comments/217821210","html_url":"https://github.com/spockframework/spock/issues/584#issuecomment-217821210","issue_url":"https://api.github.com/repos/spockframework/spock/issues/584","id":217821210,"user":{"login":"tschulte","id":203910,"avatar_url":"https://avatars.githubusercontent.com/u/203910?v=3","gravatar_id":"","url":"https://api.github.com/users/tschulte","html_url":"https://github.com/tschulte","followers_url":"https://api.github.com/users/tschulte/followers","following_url":"https://api.github.com/users/tschulte/following{/other_user}","gists_url":"https://api.github.com/users/tschulte/gists{/gist_id}","starred_url":"https://api.github.com/users/tschulte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschulte/subscriptions","organizations_url":"https://api.github.com/users/tschulte/orgs","repos_url":"https://api.github.com/users/tschulte/repos","events_url":"https://api.github.com/users/tschulte/events{/privacy}","received_events_url":"https://api.github.com/users/tschulte/received_events","type":"User","site_admin":false},"created_at":"2016-05-09T09:45:59Z","updated_at":"2016-05-09T09:45:59Z","body":"The complete example as Gradle project:\r\n\r\n[spock-methodrule.zip](https://github.com/spockframework/spock/files/254656/spock-methodrule.zip)\r\n"}}