It's a TDD/BDD framework for Clojure, based on RSpec.
Include speclj in your :dependencies
and :plugins
, and also change the :test-path
to "spec/"
:dependencies [[org.clojure/clojure "1.5.0"]]
:profiles {:dev {:dependencies [[speclj "2.5.0"]]}}
:plugins [[speclj "2.5.0"]]
:test-paths ["spec/"]
You will need Leiningen version 1.4 or later.
Include speclj in your :dev-dependencies
and change the :test-path
to "spec/"
:dev-dependencies [[speclj "2.5.0"]]
:test-path "spec/"
- Check out the source code: https://github.com/slagyr/speclj
- Build the jar file:
$ lein jar
All your 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)
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
(:require [speclj.core :refer :all]
[sample.core :refer :all]))
(describe "Truth"
(it "is true"
(should true))
(it "is not false"
(should-not false)))
(run-specs)
Your spec files should :use
the 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)
(use '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
calls.
(it "is true" ...)
Assertions. All assertions begin with should
. should
and 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.
(run-specs)
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 before
, with
, 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 speclj.main
.
$ lein spec
The command below will run all the specs found in "spec"
directory.
$ 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
To make sure you didn't break the cljs version of specljs:
$ cd cljs
$ lein translate
$ lein cljsbuild clean
$ lein cljsbuild once
Make patches and submit them along with an issue (see below).
Post issues on the speclj github project:
- Speclj 2.* requires Clojure 1.4.0+
- Clojure 1.3 is not supported by any version of Speclj due to a bug in Clojure 1.3.
Copyright (C) 2010-2013 Micah Martin All Rights Reserved.
Distributed under the The MIT License.