These are chat archives for etorreborre/specs2

13th
Dec 2016
Wiem Zine El Abidine
@wi101
Dec 13 2016 11:49
Hello @etorreborre
I work with spec2 3.8.6
I have AkkaSpec that has an implicit val actorSystem =.... and beforeAll method
When I run RootSpec that runs all Specs; the actorSystem will started and beforeAll method is not called because an Exception occurs: "org.jboss.netty.channel.ChannelException: Failed to bind to: /127.0.0.1:2554 caused by java.net.BindException: Address already in use" .
Finally I found that "RootSpec" will initialise several times all specs with all their "val"
I implement a sample example

import org.specs2.specification.BeforeAll

trait A extends BeforeAll{
val greeting = "Hello "+name
def name = ""
println (s"** $greeting")

def beforeAll(): Unit = {
println("beforeAll")
}
}
import org.specs2.Specification

class B extends Specification with A {
override def is = s2""" greeting: $e1 """
override def name = "A"

def e1 = 1 must_==1
}
import org.specs2.Specification

class AllTests extends Specification {
def is = s2"""
${"" ~ new B}
"""
}

and the display will be as follows
Hello A Hello A
Hello A Hello A
beforeAll
Hello A Hello A
Hello A Hello A
Eric Torreborre
@etorreborre
Dec 13 2016 13:00
What do you execute precisely? This: sbt> testOnly *AllTests?
Wiem Zine El Abidine
@wi101
Dec 13 2016 13:01
Yes
Eric Torreborre
@etorreborre
Dec 13 2016 13:02
I get only one Hello A in that case
Wiem Zine El Abidine
@wi101
Dec 13 2016 13:54
I try this example in other Project and I got also one "Hello A " .. That's weird.
Wiem Zine El Abidine
@wi101
Dec 13 2016 14:01
I have in build.sbt this line:
testOptions in Test := Seq(Tests.Argument(TestFrameworks.Specs2, "console", "junitxml", "html", "all", "!pandoc"))
Eric Torreborre
@etorreborre
Dec 13 2016 14:03
Can you put some println statement at the top of each of your classes to know which one is really executed? I suspect that B get executed twice
Wiem Zine El Abidine
@wi101
Dec 13 2016 14:15
in my project (with testOptions arguments) I have this display:
AllTests is running
A is running
B is running
A is running
B is running
A is running
B is running
A is running
B is running
beforeAll
A is running
B is running
A is running
B is running
A is running
B is running
A is running
B is running
and without testOptions arguments:
AllTests is running
A is running
B is running
Eric Torreborre
@etorreborre
Dec 13 2016 14:46
I am trying to reproduce and check. In the meantime my recommendation is to use lazy vals instead of vals in your specifications
Wiem Zine El Abidine
@wi101
Dec 13 2016 15:03
yes, but in my case the AkkaSpec extends RouteTest (of akka-http-testkit) that has an implicit val system..
Otherwise in this sample example (without testOptions arguments) the println in beforeAll Method is not there.