Follow the installation instructions and create the following specification in a file named HelloWorldSpec.scala
:
class HelloWorldSpec extends Specification { def is = s2"""
This is a specification to check the 'Hello world' string
The 'Hello world' string should
contain 11 characters $e1
start with 'Hello' $e2
end with 'world' $e3
"""
def e1 = "Hello world" must have size(11)
def e2 = "Hello world" must startWith("Hello")
def e3 = "Hello world" must endWith("world")
}
A org.specs2.Specification
and declaring a special is
method. This method contains both plain text describing what the application should do but also some method calls containing a more formal specification of the expected behaviour.
And this is it! Now you can execute your specification with a runner and observe the results:
> scala -cp ... specs2.run HelloWorldSpec
HelloWorldSpec
This is a specification to check the 'Hello world' string
The 'Hello world' string should
+ contain 11 characters
+ start with 'Hello'
+ end with 'world'
Total for specification HelloWorldSpec
Finished in 0 second, 58 ms
3 examples, 0 failure, 0 error
The rest of this User Guide will show you how to: