I just started using Scala and Spec2. However, I’m a little bit confusing of the acceptance style in spec2.
Could somebody explain it to me what’s the function of ! and ^ in this case. I have read at the documentation and I still don’t quite understand. I understand the unit testing pattern, but this part is really hard to understand for me.
"this is my specification" ^
"and example 1" ! e1^
"and example 2" ! e2
def e1 = success
def e2 = success
This example I got it from http://etorreborre.github.com/specs2/guide/org.specs2.guide.Structure.html
Thank you very much.
It is quite simple. As written on the page
^builds a list of fragments. Fragments can be either strings, descriptions with code blocks attached (“description” ! block) or control elements likepfor a blank line. So your example can be read as:This will be assigned as the body of the
def is =at the top of your spec class. Internally this list will then be processed and for each description there will be a line printed to the console and depending on the result of the block (if it has one) it will be colored differently.So to sum it up, it build a list of items that will be processed by the test runner.