These are chat archives for etorreborre/specs2

Jan 2017
Aleksandr Panchul
Jan 30 2017 22:33
@etorreborre , from the code above, why do we need the implicit def arbitraryAkka: Arbitrary[Akka] = Arbitrary(Gen.const(Akka())) ? I tried to switch in the Generators from String to InputStream, and it only worked when I added an implicit Arbitrary, which is breaking my plan to make the generator as a parameter for the test.
Passing the higher order functions to the test functions seemed like a nice way to avoid cut/paste of chunks of similar test routines. Are there other approaches? Maybe some kind of application-level template I could reuse in similar way.
Eric Torreborre
Jan 30 2017 22:51
In my code the Arbitrary[Akka] is used to get a new actor system for each new tested property. Also, as you can see on my example you can pass a generator to a property with the .setGen or setGen1/setGen2/setGen3 syntax (depending on the number of parameters of your property). The difficulty with you original code is that you are using a trait extending DelayedInit (via the After trait) and this seems to create compiler bugs. My work-around consists in making the actor system a bit more explicit. You can probably follow whatever approach you first tried provided that you don't use the DelayedInit trait
def myTestTemplate[T, R : AsResult](gen: Gen[T], toTest: T => R): Prop = {
   val akka = startAkka
  import akka._

   try { 
    // possibly do something here?
  } finally akka.shutdown
Aleksandr Panchul
Jan 30 2017 22:58
Thanks, it looks interesting. Actually, I mix in BeforeAfterAll to setup and remove the filesystem I use during the test. I don't think I need After in hte Akka case class. At least, I did make it work without it:
Aleksandr Panchul
Jan 30 2017 23:28
What I found out is that if I use another type inside of Gen[T], like a tuple Gen[(String, InputStream)], it does not work until I add implicit Arbitrary[(String,InputStream)]. So the test template will probably not work with T being Gen of some other types that do not have implicits. Am I right?