Welcome to specs!
| 05/07/2009 | | NEW: Easier syntax with be/have + matcher. Alpha version of literate specifications and Forms. Other improvements and fixes: run options, configuration, pending examples. |
| 04/06/2009 | specs 1.4.4 | NEW: Added a Mockito trait to use the Mockito library for mock objects. Added new command-line options. Documented the System contexts and added a way to use them with implicit vals. Changed the Maven group id to org.scala-tools.testing. See fixes and other improvements here |
| 02/12/2009 | specs 1.4.3 | NEW: Added a "-xonly" or "--failedonly" option to only display failures and errors in the console. Fixed issues and added 2 matchers. |
| 01/14/2009 | specs 1.4.2 | NEW: Upgraded to Scala-2.7.3. Added a new TeamCity runner (thanks to Stepan Koltsov). |
specs is a Behaviour-Driven-Design framework which provides:
- a simple and typed language to create specifications (your first specification in 5 minutes)
object helloWorld extends Specification {
"'hello world' has 11 characters" in {
"hello world".size must be equalTo(11)
}
"'hello world' matches 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
} "myString" must be matching("Str.*")
// or to specify xml pieces using XPath-like operators:
<a><b><c><d></d></c></b></a> must \\("c").\("d")// generates 500 different mail addresses
mailAddresses must pass { address =>
address must beMatching(companyPattern)
}object SendSpec extends Specification with JMocker {
"A Send service" should {
"publish data" in {
val mock = mock[Mailer]
// use the mock
val sendService = new SendService(mock)
sendService.publishData
// check that the mock was called
mock.send(any[Mail]) was called
}
}
}object compositeSpec extends Specification {
"A composite spec" isSpecifiedBy (okSpec, koSpec)
}"A stack below full capacity" definedAs(belowCapacity) should {
behave like "A non-empty stack below full capacity"
"add to the top when sent #push" in {
stack push 3
stack.top mustBe 3
}
}- data tables to group several data examples at once:
object addOperationSpec extends Specification with org.specs.util.DataTables {
"provide an add operation" in {
"a" | "b" | "result" |>
1 ! 2 ! 3 |
5 ! 2 ! 7 |
3 ! 0 ! 3 | { (a, b, c) => { a + b must_== c } }
}
}The first time
You can download the current library distribution (or get it with Maven) and execute:
java -cp specs-1.5.0.jar;specs-1.5.0-tests.jar;scalacheck-1.5.jar;scala-library-2.7.4.jar;junit-4.5.jar;cglib-2.1_3.jar;asm-1.5.3.jar;objenesis-1.1.jar;hamcrest-all-1.1.jar;jmock-2.4.0.jar;mockito-all-1.7.0.jar;wikitext.core-0.9.4.I20090220-1600-e3x.jar;wikitext.textile-0.9.4.I20090220-1600-e3x.jar;markdownj-0.3.0-1.0.2b4.jar org.specs.allRunner
Then you should see the whole specification for the specs project, ending with:
Total for specification "The specs and unit tests for the specs project": Finished in 1 minute 10 seconds, 703 ms 854 examples, 7721 expectations, 0 failure, 0 error
tested with Scala 2.7.4-final
Happy specs!