Skip to content

Instantly share code, notes, and snippets.

(declare *the-answer*) ; outside of a describe
(around [it]
(binding [*the-answer* 42]
(it)))
(it "knows the answer"
(should= 42 *the-answer*))
(given [the-answer]
(expect (= 42 the-answer))
42)
(given [the-answer]
(expect (= 42 the-answer))
42)
;;; or, if you want to define more context
(given [x y]
(expect x (* 2 y))
42 84
20 (inc (dec 10)))
(expect (interaction (one "hello" {:a :b :c {:dd :ee :ff :gg}}))
(do
(one "hello")
(one "hello" "world" "here")
(one "hello" {:a 1 2 3})))
@jaycfields
jaycfields / some.clj
Created December 23, 2013 19:54
let can be the first binding to doseq, and it will be executed exactly 1 time.
(doseq [:let [a (do (println 1) 99)]
x [11 12]]
(println x a))
;; output:
;; 1
;; 11 99
;; 12 99
(defmulti nan->keyword class :default :default)
(defmethod nan->keyword java.util.Map [m]
(if (instance? clojure.lang.IRecord m)
(nan->keyword (into {} (seq m)))
(let [f (fn [[k v]] [k (if (and (number? v) (Double/isNaN v)) :DoubleNaN v)])]
(expectations.clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))))
(defmethod nan->keyword java.util.List [m]
(map #(if (and (number? %) (Double/isNaN %)) :DoubleNaN %) m))
(ns leiningen.hooks.expand-resource-paths
(:use [clojure.java.io :only [as-file]])
(:import [java.io File])
(:require [robert.hooke]
[leiningen.javac]
[org.satta.glob :as glob]))
(setq c-default-style "gnu")
(defun my-indent-setup ()
(c-set-offset 'arglist-intro '+))
(add-hook 'java-mode-hook 'my-indent-setup)

Unit Test

The definition of Unit Test is quite general:

In computer programming, unit testing is a method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures are tested to determine if they are fit for use. [...] A unit could be an entire module, but it is more commonly an individual function or procedure. --Wikipedia

Types of Tests

Before we get back to concrete examples there are a few terms we'll want to define: State Verification, Behavior Verification, Solitary Unit Test, and Sociable Unit Test. These terms have plenty of definitions available on the Internet; unfortunately, many of those definitions differ and some are in direct conflict. This chapter will define those terms for the context of this book.

Strongly Recommended Reference Material