{"action":"created","issue":{"url":"https://api.github.com/repos/etorreborre/specs2/issues/263","labels_url":"https://api.github.com/repos/etorreborre/specs2/issues/263/labels{/name}","comments_url":"https://api.github.com/repos/etorreborre/specs2/issues/263/comments","events_url":"https://api.github.com/repos/etorreborre/specs2/issues/263/events","html_url":"https://github.com/etorreborre/specs2/issues/263","id":33470543,"number":263,"title":"Isolated doesn't create a new spec instance for each scalacheck test","user":{"login":"caspark","id":931544,"avatar_url":"https://avatars.githubusercontent.com/u/931544?v=3","gravatar_id":"","url":"https://api.github.com/users/caspark","html_url":"https://github.com/caspark","followers_url":"https://api.github.com/users/caspark/followers","following_url":"https://api.github.com/users/caspark/following{/other_user}","gists_url":"https://api.github.com/users/caspark/gists{/gist_id}","starred_url":"https://api.github.com/users/caspark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caspark/subscriptions","organizations_url":"https://api.github.com/users/caspark/orgs","repos_url":"https://api.github.com/users/caspark/repos","events_url":"https://api.github.com/users/caspark/events{/privacy}","received_events_url":"https://api.github.com/users/caspark/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-05-14T08:10:55Z","updated_at":"2015-04-10T01:53:22Z","closed_at":"2014-05-15T05:54:28Z","body":"(or at least, that's my uneducated summary of the problem)\r\n\r\nIf you have a test like this:\r\n\r\n````\r\npackage com.atlassian.crowd.manager.login.util\r\n\r\nimport org.specs2.mock.Mockito\r\nimport org.specs2.mutable.SpecificationWithJUnit\r\nimport org.specs2.ScalaCheck\r\n\r\nobject TestPieces {\r\n  trait MyInterface {\r\n    def doSomething(): Unit\r\n  }\r\n\r\n  class MySystemUnderTest(myInterface: MyInterface) {\r\n    def doTest() = myInterface.doSomething\r\n  }\r\n}\r\n\r\nclass MyDemoTest extends SpecificationWithJUnit with Mockito with ScalaCheck {\r\n  isolated\r\n\r\n  val myMock = mock[TestPieces.MyInterface]\r\n  val underTest = new TestPieces.MySystemUnderTest(myMock)\r\n\r\n  \"show-problem\" in propNoShrink {\r\n    (myStr: String) ⇒\r\n      //org.mockito.Mockito.reset(myMock)\r\n      underTest.doTest\r\n      there was one(myMock).doSomething\r\n  }\r\n}\r\n````\r\n\r\nthen `show-problem` will fail. If you uncomment the line to reset the mocks, it won't fail.\r\n\r\nPresumably this is because specs2 doesn't create a new instance of the spec for each scalacheck \"test case\".\r\n\r\nThis may not technically be a bug, since the docs say \"The isolated argument changes the execution method so that each example is executed in a brand new instance of the Specification\", but it sure goes against the spirit of isolated and it'd be great if we didn't have to reset our mocks or create mocks from within the test code.\r\n\r\nI also tried to use scopes, to no avail:\r\n````\r\n  \"show-problem-2\" in new MyScope {\r\n    propNoShrink {\r\n      (myStr: String) ⇒\r\n        //org.mockito.Mockito.reset(myMock)\r\n        underTest.doTest\r\n        there was one(myMock).doSomething\r\n    }.set(minTestsOk = 10)\r\n  }\r\n\r\n  trait MyScope extends Scope {\r\n    val myMock = mock[TestPieces.MyInterface]\r\n    val underTest = new TestPieces.MySystemUnderTest(myMock)\r\n  }\r\n````\r\n\r\nIt makes sense to me that that did not work because the scope wraps the `propNoShrink`, but I couldn't work out how to get it to compile with scope inside the `propNoShrink` block unless I have the block return `()`:\r\n\r\n````\r\n  \"show problem\" in\r\n    propNoShrink {\r\n      (myStr: String) ⇒\r\n        //org.mockito.Mockito.reset(myMock)\r\n        new MyScope {\r\n          underTest.doTest\r\n          there was one(myMock).doSomething\r\n        }\r\n        ()\r\n    }.set(minTestsOk = 10000)\r\n````\r\n\r\nSo then I figured I'll do `implicit def scopeToProp(u: =>Scope): Prop = ()` but then the test passes even if asserts in the scope fail, so clearly I'm missing a piece here."},"comment":{"url":"https://api.github.com/repos/etorreborre/specs2/issues/comments/91399272","html_url":"https://github.com/etorreborre/specs2/issues/263#issuecomment-91399272","issue_url":"https://api.github.com/repos/etorreborre/specs2/issues/263","id":91399272,"user":{"login":"caspark","id":931544,"avatar_url":"https://avatars.githubusercontent.com/u/931544?v=3","gravatar_id":"","url":"https://api.github.com/users/caspark","html_url":"https://github.com/caspark","followers_url":"https://api.github.com/users/caspark/followers","following_url":"https://api.github.com/users/caspark/following{/other_user}","gists_url":"https://api.github.com/users/caspark/gists{/gist_id}","starred_url":"https://api.github.com/users/caspark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caspark/subscriptions","organizations_url":"https://api.github.com/users/caspark/orgs","repos_url":"https://api.github.com/users/caspark/repos","events_url":"https://api.github.com/users/caspark/events{/privacy}","received_events_url":"https://api.github.com/users/caspark/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T01:53:22Z","updated_at":"2015-04-10T01:53:22Z","body":"Specs2 v3.x equivalent:\r\n\r\n```scala\r\n/**\r\n * Allow using specs2 scopes inside scalacheck blocks; workaround for https://github.com/etorreborre/specs2/issues/263\r\n * This is only safe to mix in for mutable specifications.\r\n */\r\ntrait ScalaCheckScopes extends ResultPropertyImplicits {\r\n  //importing only into this scope because it doesn't really belong to the rest of the spec\r\n  import org.scalacheck.Prop\r\n  import org.specs2.execute.Success\r\n  import scala.language.implicitConversions\r\n\r\n  implicit def scopeToProp(u: ⇒ Scope): Prop = { u; resultProp(Success()) }\r\n}\r\n```"}}