Closed sritchie closed 11 years ago
Darn. It's a bug.
"Folded prerequisites"
https://github.com/marick/Midje/wiki/Folded-prerequisites
are only unfolded when they appear in (provided...), not in background
.
One workaround, if you need it, is to unfold the prerequisite yourself:
(against-background
(black-hole ..num..) => ..black-hole-value..
(square ..black-hole-value..) => 9
I'll file an issue.
On Oct 2, 2011, at 3:20 PM, Sam Ritchie wrote:
I came across an issue with the use against-background in folded prerequisites. Let's say I'm testing these functions:
(defn square [x](* x x))
(defn black-hole "Throws an exception, ALWAYS!" [& _](throw %28IllegalArgumentException.)))
(defn square->string [x](str %28square %28black-hole x%29%29))
And want to mock out
(square (black-hole x))
.provided
does what I want, and never actually passes anything into the black hole:(fact "This pass just fine." (square->string ..num..) => "9" (provided (square (black-hole ..num..)) => 9))
while
against-background
actually passes in the arguments:(fact "This one dies!" (square->string ..num..) => "9" (against-background (square (black-hole ..num..)) => 9))
This examples a little crazy, but any inner function that can't accept a string (or whatever else I use for the mocked variable) will fail in the
against-background
case.Thanks, Midje is awesome! Sam
Reply to this email directly or view it on GitHub: https://github.com/marick/Midje/issues/54
Brian Marick, Artisanal Labrador Now working at http://path11.com Contract programming in Ruby and Clojure Occasional consulting on Agile
The specific problem is that fakes/unfolding-step
is only called in the expansion of semi-sweet/expect
form. Something similar will have to be done somewhere around prerequisites/expand-prerequisites-into-fake-calls
Great, and thanks for the workaround, that looks good.
Poking at this code, and it is poking me back, unfortunately. It really seems to me like unfolded fakes should work in background forms. the inconsistency makes me really want to fix this bug.
I factored this function out of unfold-expect-form__then__stay_put
in fakes.clj, thinking I could use it in extract-state-descriptions+fakes
in background.clj to unfold all of the fakes:
(defn unfold-all-pending-fakes [pending]
(loop [[finished pending substitutions] [[] pending {}]]
(if (empty? pending)
finished
(recur (unfolding-step finished pending substitutions)))))
Tried to use it like:
is-start-of-checking-arrow-sequence?
(let [arrow-seq (take-arrow-sequence in-progress)]
(recur (conj expanded (mapcat tag-as-background-fake (unfold-all-pending-fakes [arrow-seq])))
(drop (count arrow-seq) in-progress)))
That was a massive fail as I don't know if I'm inches from getting this working or miles away.
Any comments on this approach, Brian? Is it helpful to you? Is it way off?
We're going to hold off on fixing this until after we rework the approach we use for background/against-background.
I'm closing this and consolidating all the "background" issues into a single issue that can serve to help us avoid mistakes next go-round.
I came across an issue with the use against-background in folded prerequisites. Let's say I'm testing these functions:
And want to mock out
(square (black-hole x))
.provided
does what I want, and never actually passes anything into the black hole:while
against-background
actually passes in the arguments:This examples a little crazy, but any inner function that can't accept a string (or whatever else I use for the mocked variable) will fail in the
against-background
case.Thanks, Midje is awesome! Sam