Skip to content

Add an API for declaring a series of return valuesΒ #10

Open
@dchelimsky

Description

I just wrote something like this in a project to supply different return values each time a function is called:

(def times (atom []))

(defn set-times [new-times]
  (reset! times (into [] (reverse new-times))))

(defn next-time []
  (let [ret (peek @times)]
    (swap! times pop)
    ret))

(deftest test-times
  (set-times [#nu/time "2022-04-01T10:30:00Z"
              #nu/time "2022-04-01T10:30:01Z"])
  (mfn/providing [(time/now) (mfn/calling next-time)]
    (is (= #nu/time "2022-04-01T10:30:00Z" (time/now)))
    (is (= #nu/time "2022-04-01T10:30:01Z" (time/now)))))

I'd be great to just write something like this:

(deftest test-times
  (mfn/providing [(time/now) (mfn/returning #nu/time "2022-04-01T10:30:00Z"
                                            #nu/time "2022-04-01T10:30:01Z")]
    (is (= #nu/time "2022-04-01T10:30:00Z" (time/now)))
    (is (= #nu/time "2022-04-01T10:30:01Z" (time/now)))))

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions