Multiple responses for the same provided

30 views
Skip to first unread message

Eduard Céspedes

unread,
Jun 17, 2014, 6:44:49 AM6/17/14
to mi...@googlegroups.com
Is it possible to return different responses whenever you are invoking the same provided multiple times?

Something like this:

(defn f2 [x] (* x x))
(defn f1 [x] (+ (f2 x) (f2 x)))

(fact "testing multiple provided"
  (f1 2) => 12
  (provided (f2 2) => 5)
  (provided (f2 2) => 7))


Right now I solve it like this:

(defn f2 [x] (* x x))
(defn f1 [x] (+ (f2 x) (f2 x)))

(def ^:private mutable-value (atom 5))

(fact "testing multiple provided"
  (let [value (fn []
                (do
                  (swap! mutable-value inc)
                  @mutable-value))]
    (f1 2) => 12
    (provided (f2 2) => (value))))


Is there any other way of doing it? Am I missing something really obvious? 

Thanks!

Brian Marick

unread,
Jun 17, 2014, 9:39:25 AM6/17/14
to mi...@googlegroups.com

On Jun 17, 2014, at 5:44 AM, Eduard Céspedes <had...@gmail.com> wrote:

> Is it possible to return different responses whenever you are invoking the same provided multiple times?

=streams=>

https://github.com/marick/Midje/wiki/Streaming-prerequisites

--------
Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo

Eduard Céspedes

unread,
Jun 19, 2014, 2:18:46 AM6/19/14
to mi...@googlegroups.com
Thanks, I didn't read all the documentation carefully. My fault!
Reply all
Reply to author
Forward
0 new messages