Dear all,
I was trying to set up a Scope for my examples which needed some setup and cleaning procedure.
I noticed that, however, if I use a trait which extends BeforeAfter and I do the following:
Trait MyContextWithSetupAndCleanup extends BeforeAfter
"When something " in new MyContextWithSetupAndCleanup ("testSpace3", "testGroup3") {
result must beSuccessful
}
The code in the MyContextWithSetupAndCleanup Before method is executed twice:
1 When the example is created
1 when the example is executed
I am using a mutable specification with sequential.
Am I making wrong usage of specs2 features?
Best
Edmondo Porcu
Hello Eric,
I found out that if instead of a trait you use a class and you put something in the constructor, things don’t work as you expect.
Without code inside the constructor:
@RunWith(classOf[JUnitRunner])
class Spec2ProblemWithBeforeAfter extends Specification{
abstract class test extends BeforeAfter {
def before = "before".pp
def after = "after".pp
}
sequential
"The BeforeAfter before and before" should {
"Not be called twice" in new test{
"a" must_== "a"
}
}
}
Testing started at 10:39 ...
before
afterThe BeforeAfter before and before should
Not be called twice
Process finished with exit code 0
With code inside the constructor:
@RunWith(classOf[JUnitRunner])
class Spec2ProblemWithBeforeAfter extends Specification{
abstract class test extends BeforeAfter {
println("hello")
def before = "before".pp
def after = "after".pp
}
sequential
"The BeforeAfter before and before" should {
"Not be called twice" in new test{
"a" must_== "a"
}
}
}
before
hello
after
before
after
Process finished with exit code 0
I have the feeling that using scala.DelayedInit inside BeforeAfter might be tricky…
Best regards
Edmondo
--
You received this message because you are subscribed to the Google Groups "specs2-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
specs2-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
In my case it was only lazy vals.
What do you suggest?
Best Regards