Specs BeforeAfter in immutable specification ignored

15 views
Skip to first unread message

Edmondo Porcu

unread,
May 23, 2015, 8:17:44 AM5/23/15
to specs2...@googlegroups.com
Hello,

I have some code which looks like the following

class Context(blah:String) extends specification.BeforeAfter {
 //  before and after
}

class Specification1 extends Specification{
 
    class Specification1Context(blah:String, int:id) extends Context(blah){
       
     def e1 = id === 3
      }

def is = s2""" The specification example should be wrapped in beforeAfter ${new SpecificationContext("hello",3)}"""

 }

And the beforeAfter is not called. Any idea of what I might be doing wrong?

etorreborre

unread,
May 24, 2015, 6:24:41 AM5/24/15
to specs2...@googlegroups.com, edmond...@gmail.com
A BeforeAfter object will invoke the before/after methods if you use the `apply` method so this should work:

case class Context(blah:String) extends specification.BeforeAfter {
 //  before and after
}

class Specification1 extends Specification{
 
    class Specification1Context(blah:String, int:id) extends Context(blah){       
         def e1 = apply { id === 3 }
      }

    def is = s2""" The specification example should be wrapped in beforeAfter ${SpecificationContext("hello",3).e1}"""
 }

Eric.

edmondo1984

unread,
May 24, 2015, 7:40:02 AM5/24/15
to specs2...@googlegroups.com, edmond...@gmail.com
I just read twice the documentation and find that out. What a beginner error!
Reply all
Reply to author
Forward
0 new messages