Repl tools

Matt Freeman edited this page Sep 27, 2015 · 18 revisions
Clone this wiki locally

When facts are loaded, they're converted into values (functions with a particular calling convention) that are stored in a compendium. By default, they're also checked as they're loaded. (Although that's a configuration setting.) The last fact checked is remembered specially.

The repl tools allow you to work with that compendium. They also support autotesting, which tracks changes to files and reloads (and rechecks) them as needed.

This page gives a brief summary of the various commands. Some of them work with fact metadata.

Loading facts into memory and working with them. (Details)

  • load-facts: Load namespaces and check facts.
(use 'midje.repl)  ;; namespace of the midje repl functions
(load-facts)       ;; Initially, load everything. Subsequently, load the last "working set"
(load-facts :all)  ;; Load everything.
(load-facts 'proj.namespace 'proj.other.namespace)
(load-facts 'proj.subdir.*)  ;; Load a namespace tree.

The :all argument replaces everything in the compendium. When explicit namespaces are given, existing facts from those namespaces are forgotten, then the namespaces are reloaded. Facts from other namespaces stay in the compendium. That is, suppose that you give the following two commands:

(load-facts 'proj.util.*)
(load-facts 'proj.chairs.*)

At the end of the second command, both sets of namespaces are in the compendium.

Examples of other features:

(load-facts 'namespace :print-facts)  ;; Adjust print verbosity while loading

;; Load facts works with metadata
(load-facts :integration)  ;; Load only integration tests
(load-facts (complement :integration) ;; Load non-integration tests
(load-facts "cute")     ;; Load only facts with "cute" in their names (doc strings)
(load-facts #"cute[0-6]" ;; Load only facts whose names match the regular expression
(load-facts some-arbitrary-function-over-a-metadata-map)
  • check-facts: Check some or all of the loaded facts again (without reloading them)
(check-facts)                       ;; Recheck same facts over again.
(check-facts *ns* 'proj.t-cursor)   ;; Check a subset of the compendium by namespace.
(check-facts :all)                  ;; Check everything (if a previous command narrowed the "working set")

check-facts takes the same filter and verbosity arguments as load-facts.

  • forget-facts: Forget some or all of the loaded facts
(forget-facts :all)                 ;; Forget everything
(forget-facts *ns* 'some.namespace) ;; Forget by namespace
(forget-facts)                      ;; Forget the current "working set".

forget-facts takes the same filter arguments as load-facts.

  • fetch-facts: Return a sequence of some or all of the loaded facts.
(fetch-facts :all)                  ;; Return all the facts in the compendium
(fetch-facts)                       ;; Fetch the current working set.
(fetch-facts *ns* 'some-namespace)  ;; Fetch by namespace

fetch-facts takes the same filter arguments as load-facts.

  • check-one-fact: Check a fact returned from fetch-facts.
(map check-one-fact (fetch-facts))

Autotesting (Details)

(autotest)
(autotest :dirs "test/midje/util" "src/midje/util")
(autotest :filter :core) ; Check only core facts.
(autotest :filter "can do x y z with constraint a") ; Check facts by their name.


(autotest :pause)
(autotest :resume)
(autotest :stop)

The most recently checked fact

  • recheck-fact: Check the last fact checked again.
  • last-fact-checked: Returns previous fact as a value.
  • source-of-last-fact-checked: Show source of previous fact.
user=> (fact (+ 1 1) => 3)

FAIL at (NO_SOURCE_FILE:1)
    Expected: 3
      Actual: 2
false
user=> (recheck-fact)

FAIL at (NO_SOURCE_FILE:1)
    Expected: 3
      Actual: 2
FAILURE: 1 claim was not confirmed. 
false
user=> (source-of-last-fact-checked)
(fact (+ 1 1) => 3)
user=> (check-one-fact (last-fact-checked))

FAIL at (NO_SOURCE_FILE:1)
    Expected: 3
      Actual: 2
false