2

This is the skeleton of what I want to achieve

(let [temp-dir (create-temp-dir)]          ; setup
  (fact
    (do-something-with temp-dir) => true)  ; actual test
  (delete-dir temp-dir))                   ; teardown

The midje testing framework gives access to lexical scope (scroll down towards the end). So this is what I'd expect to work:

(against-background
  (around :facts
    (let [temp-dir (create-temp-dir)]
      (do ?form (delete-dir temp-dir))))
  (fact (do-something-with temp-dir) => true))

But the compiler complains that it can't resolve the symbol temp-dir. Any idea how to make this work?

Adam Schmideg
  • 10,590
  • 10
  • 53
  • 83

1 Answers1

1

You're missing the square brackets around your wrappers. From the link you included:

zero or more wrappers can be found in three different forms:

(against-background [ wrappers ] ...)

The wrappers apply to all the forms within the against-background.

(fact ... (against-background wrappers ) ...)

Semantically, this is the same as an against-background that wraps this single fact. The against-background form can appear anywhere in a fact's top-level forms, and there can be more than one. Note that it's not surrounded by [].

(background wrappers ...)

Diego Basch
  • 12,764
  • 2
  • 29
  • 24