Skip to content

Partial prerequisites

marick edited this page Feb 28, 2013 · 10 revisions

Consider this code:

(fact 
   (f 8) => "lorem ipsum"
   (provided
     (helper 8) => 11))

If f calls helper with the value 5555, Midje will report a "You never said `helper` would be needed with these arguments" failure. That's usually what you want.

But not always.

Suppose f has existed for a long time, and you just want to make it handle a new special case, which will in turn require helper to handle its own new special case. Because you're working top-down, you want to work on f first while using a prerequisite to describe the helper's new behavior:

(fact "`f` now works on negative numbers"
   (f -1) => "muspi merol"
   (provided
     (helper -1) => 11))

But what if f uses the helper twice, once to elicit the new behavior, once for the old behavior? You'd get the "no such prerequisite" complaint about the old-behavior call. To fix that, you'd have to add a prerequisite that describes what helper already automatically does. Sometimes doing that makes the fact more clear, but sometimes it's just annoying.

Therefore: if there's a call to a function, like helper, that:

  • has at least one prerequisite defined for it,
  • but none of the prerequisites match the arguments in the call,
  • and helper is already defined as a function,
  • and the configuration option :partial-prerequisites is set to true, then:

the existing function will be applied to the given arguments.

Clone this wiki locally