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 not always what you want.

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 "external now works on negative numbers"
   (f -1) => "muspi merol"
   (provided
     (helper -1) => 11))

But what if f uses internal more than once? (Or what if something else f calls happens to use helper?) To fix that, you'd have to add a prerequisite describing helper's pre-existing behavior. 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