{"action":"created","issue":{"url":"https://api.github.com/repos/kotlintest/kotlintest/issues/77","repository_url":"https://api.github.com/repos/kotlintest/kotlintest","labels_url":"https://api.github.com/repos/kotlintest/kotlintest/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/kotlintest/kotlintest/issues/77/comments","events_url":"https://api.github.com/repos/kotlintest/kotlintest/issues/77/events","html_url":"https://github.com/kotlintest/kotlintest/issues/77","id":165924922,"number":77,"title":"Extensions like junit rules","user":{"login":"sksamuel","id":743706,"avatar_url":"https://avatars.githubusercontent.com/u/743706?v=3","gravatar_id":"","url":"https://api.github.com/users/sksamuel","html_url":"https://github.com/sksamuel","followers_url":"https://api.github.com/users/sksamuel/followers","following_url":"https://api.github.com/users/sksamuel/following{/other_user}","gists_url":"https://api.github.com/users/sksamuel/gists{/gist_id}","starred_url":"https://api.github.com/users/sksamuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sksamuel/subscriptions","organizations_url":"https://api.github.com/users/sksamuel/orgs","repos_url":"https://api.github.com/users/sksamuel/repos","events_url":"https://api.github.com/users/sksamuel/events{/privacy}","received_events_url":"https://api.github.com/users/sksamuel/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/kotlintest/kotlintest/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"helmbold","id":5079980,"avatar_url":"https://avatars.githubusercontent.com/u/5079980?v=3","gravatar_id":"","url":"https://api.github.com/users/helmbold","html_url":"https://github.com/helmbold","followers_url":"https://api.github.com/users/helmbold/followers","following_url":"https://api.github.com/users/helmbold/following{/other_user}","gists_url":"https://api.github.com/users/helmbold/gists{/gist_id}","starred_url":"https://api.github.com/users/helmbold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helmbold/subscriptions","organizations_url":"https://api.github.com/users/helmbold/orgs","repos_url":"https://api.github.com/users/helmbold/repos","events_url":"https://api.github.com/users/helmbold/events{/privacy}","received_events_url":"https://api.github.com/users/helmbold/received_events","type":"User","site_admin":false},"assignees":[{"login":"helmbold","id":5079980,"avatar_url":"https://avatars.githubusercontent.com/u/5079980?v=3","gravatar_id":"","url":"https://api.github.com/users/helmbold","html_url":"https://github.com/helmbold","followers_url":"https://api.github.com/users/helmbold/followers","following_url":"https://api.github.com/users/helmbold/following{/other_user}","gists_url":"https://api.github.com/users/helmbold/gists{/gist_id}","starred_url":"https://api.github.com/users/helmbold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helmbold/subscriptions","organizations_url":"https://api.github.com/users/helmbold/orgs","repos_url":"https://api.github.com/users/helmbold/repos","events_url":"https://api.github.com/users/helmbold/events{/privacy}","received_events_url":"https://api.github.com/users/helmbold/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/kotlintest/kotlintest/milestones/4","html_url":"https://github.com/kotlintest/kotlintest/milestones/2.0","labels_url":"https://api.github.com/repos/kotlintest/kotlintest/milestones/4/labels","id":1854867,"number":4,"title":"2.0","description":null,"creator":{"login":"helmbold","id":5079980,"avatar_url":"https://avatars.githubusercontent.com/u/5079980?v=3","gravatar_id":"","url":"https://api.github.com/users/helmbold","html_url":"https://github.com/helmbold","followers_url":"https://api.github.com/users/helmbold/followers","following_url":"https://api.github.com/users/helmbold/following{/other_user}","gists_url":"https://api.github.com/users/helmbold/gists{/gist_id}","starred_url":"https://api.github.com/users/helmbold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helmbold/subscriptions","organizations_url":"https://api.github.com/users/helmbold/orgs","repos_url":"https://api.github.com/users/helmbold/repos","events_url":"https://api.github.com/users/helmbold/events{/privacy}","received_events_url":"https://api.github.com/users/helmbold/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":10,"state":"open","created_at":"2016-06-29T11:24:29Z","updated_at":"2016-09-22T20:09:34Z","due_on":null,"closed_at":null},"comments":15,"created_at":"2016-07-16T11:15:58Z","updated_at":"2016-09-25T18:46:50Z","closed_at":null,"body":"See https://reddit.com/r/Kotlin/comments/4qmawt/spek_vs_kotlintest/"},"comment":{"url":"https://api.github.com/repos/kotlintest/kotlintest/issues/comments/249438807","html_url":"https://github.com/kotlintest/kotlintest/issues/77#issuecomment-249438807","issue_url":"https://api.github.com/repos/kotlintest/kotlintest/issues/77","id":249438807,"user":{"login":"helmbold","id":5079980,"avatar_url":"https://avatars.githubusercontent.com/u/5079980?v=3","gravatar_id":"","url":"https://api.github.com/users/helmbold","html_url":"https://github.com/helmbold","followers_url":"https://api.github.com/users/helmbold/followers","following_url":"https://api.github.com/users/helmbold/following{/other_user}","gists_url":"https://api.github.com/users/helmbold/gists{/gist_id}","starred_url":"https://api.github.com/users/helmbold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helmbold/subscriptions","organizations_url":"https://api.github.com/users/helmbold/orgs","repos_url":"https://api.github.com/users/helmbold/repos","events_url":"https://api.github.com/users/helmbold/events{/privacy}","received_events_url":"https://api.github.com/users/helmbold/received_events","type":"User","site_admin":false},"created_at":"2016-09-25T18:46:50Z","updated_at":"2016-09-25T18:46:50Z","body":"With an around advice it would look like this:\r\n\r\n```kotlin\r\nval callable = Callable {\r\n    performBeforeEach(spec, testCase)\r\n    try {\r\n        performAroundEach(spec, testCase)\r\n    } catch (e: Throwable) {\r\n        Failure(testCase.description, e)\r\n    }\r\n}\r\n```\r\n\r\n`performAroundEach` in the same class ( `TestBase`) would look like this:\r\n\r\n```kotlin\r\n  private fun performAroundEach(spec: TestBase, testCase: TestCase): Unit {\r\n    spec.extensions.forEach { extension ->\r\n      val context = TestCaseContext(spec = this, testCase = testCase)\r\n      extension.aroundEach(context)\r\n    }\r\n  }\r\n```\r\n\r\nThe interface for extensions:\r\n\r\n```kotlin\r\ninterface SpecExtension {\r\n  fun aroundEach(context: TestCaseContext) {\r\n    context.proceed()\r\n  }\r\n  // ...\r\n}\r\n```\r\n\r\nAn implementation would look like this:\r\n\r\n```kotlin\r\nobject Timer : SpecExtention {\r\n    override fun aroundEach(context: TestCaseContext) {\r\n        val startTime = System.currentTimeMillis()\r\n\r\n        context.proceed()\r\n\r\n        val endTime = System.currentTimeMillis()\r\n        val duration = endTime - startTime\r\n        println(duration)\r\n    }\r\n}\r\n```\r\n\r\nFor my eyes it is simple an beautiful. The only thing you have to remember is to call `proceed`. But that is the same with AspectJ advices and Servlet filters ...\r\n"}}
{"actor":{"display_login":"helmbold"}}