(pronounced "speckle" [spek-uhl])
You will need Leiningen version 1.4 or later.
Leiningen version 2.0 or later
Include speclj in your
:plugins, and also change the
:dependencies [[speclj "2.1.2"] [org.clojure/clojure "1.4.0"]] :plugins [[speclj "2.1.2"]] :test-paths ["spec/"]
Leiningen version 1.x
Include speclj in your
:dev-dependencies and change the
:dev-dependencies [[speclj "2.1.2"]] :test-path "spec/"
- Check out the source code: https://github.com/slagyr/speclj
Build the jar file:
$ lein jar
speclj code should go into a a directory named
spec at the root of your project. Conventionally, the
spec directory will mirror the
src directory structure except that all the
spec files will have the '_spec.clj' postfix.
| sample_project |-- project.clj |-- src |-- sample |-- core.clj | (All your other source code) |-- spec |-- sample |-- core_spec.clj | (All your other test code)
A Sample Spec File
Checkout this example spec file. It would be located at
sample_project/spec/sample/core_spec.clj. Below we'll look at it piece by piece.
(ns sample.core-spec (:use [speclj.core] [sample.core])) (describe "Truth" (it "is true" (should true)) (it "is not false" (should-not false))) (run-specs)
Your spec files should
speclj.core in it's entirety. It's a clean namespace and you're likely going to use all the definitions within it. Don't forget to pull in the library that you're testing as well (sample.core in this case).
(:use [speclj.core] [sample.core])
describe is the outer most container for specs. It takes a
String name and any number of spec components.
(describe "Truth" ...)
it specifies a characteristic of the subject. This is where assertions go. Be sure to provide good names as the first parameter of
(it "is true" ...)
should and should-not
Assertions. All assertions begin with
should-not are just two of the many assertions available. They both take expressions that they will check for truthy-ness and falsy-ness respectively.
(should ...) (should-not ...)
At the very end of the file is an invocation of
(run-specs). This will invoke the specs and print a summary. When running a suite of specs, this call is benign.
There are several ways to make assertions. They are documented on the wiki: Should Variants
it or characteristics are just one of several spec components allowed in a
describe. Others like
around, etc are helpful in keeping your specs clean and dry. Check out the listing on the wiki: Spec Components
Speclj includes a Leiningen task to execute
$ lein spec
Running All Specs at Once
The command below will run all the specs found in
$ java -cp <...> speclj.main
The command below will start a process that will watch the source files and run spec for any updated files.
$ java -cp <...> speclj.main -a
You can also run the watcher through Leiningen. The benefit of that is that the color of the output is preserved.
$ lein spec -a
There are several options for the runners. Use the
--help options to see them all. Or visit Command Line Options.
$ java -cp <...> speclj.main --help
- Source code: https://github.com/slagyr/speclj
- Wiki: https://github.com/slagyr/speclj/wiki
- Email List: http://groups.google.com/group/speclj
speclj uses Leiningen version 1.4.0.
Clone the master branch, build, and run all the tests:
git clone https://github.com/slagyr/speclj.git cd speclj lein javac lein spec
Make patches and submit them along with an issue (see below).
Post issues on the speclj github project:
Copyright (C) 2010 Micah Martin All Rights Reserved.
Distributed under the The MIT License.