Skip to content

Partial prerequisites

marick edited this page Nov 7, 2011 · 10 revisions

This is an experimental feature, available starting with Midje 1.3-alpha5

Suppose you have a function external that uses internal. You want to make external handle a new special case, which will require internal to handle its own new special case. Because you're working top-down, you want to work on external first while using a prerequisite to describe internal's new behavior:

(fact "external works on negative numbers"
   (external -1) => "lorem ipsum"
   (provided
     (internal -1) => 11))

But what if external uses internal more than once? (Or what if something else external calls happens to use internal?) In earlier versions of Midje, you'd have to add a prerequisite describing that 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 internal, that:

  • has at least one prerequisite defined for it,
  • but none of the prerequisites match the arguments in the call,
  • and internal is already defined as a function, then

the existing function will be applied to the given arguments.

Details

The old behavior continues if internal was defined in one of these two ways:

(declare internal)
(unfinished internal)

Strictly, this change is not backwards compatible. However, I believe it's only visible because a failing test now either passes or else fails for a different reason. That is, the test previously failed with the "You never said internal would be needed with these arguments" message, but now it calls the real internal (which might make the test pass, or might deliver an unexpected result, making the test fail with an "actual result didn't agree with expected result" message).

Clone this wiki locally