4

I have recently started using the Clojure test framework expectations. As part of my test, I have a data set that I want to reset to its original value before the start of a new test/expect statement.

In clojure.test, I would just create a fixture and call (use-fixtures :each my-fixture-fn).

I've searched for good examples of how to do this in expectations but haven't had any luck yet. Could anyone provide a concrete example of how to implement a fixture that runs before each test in expectations?

1 Answers1

1

It is possible to use a let statement with expect. Maybe something like this will do the job for you (untested pseudocode):

(expect 
 (let [dataset {val: "original values"}]
  (function-to-be-tested val:))
 expected-return-value)

This real code works out of the box to show the principle:

(expect (let [ar [1 2 3]]
   (first ar)) 2)

It returns the following error message as expected:

failure in (core_test.clj:9) : image-lib.core-test
(expect (let [ar [1 2 3]] (first ar)) 2)

       expected: 1
            was: 2

Ran 2 tests containing 2 assertions in 17 msecs
1 failures, 0 errors.
Tests completed at 10:59:45.435
Iain
  • 300
  • 2
  • 13
  • Thanks lain. I had found the (expect-let ) fn after digging around in source but hadn't thought of using a (let ) fn like a fixture. That helps a lot! – Jared Holmberg Jan 07 '16 at 14:14