Mock db data for unit tests

175 views
Skip to first unread message

Mark Watson

unread,
Mar 7, 2014, 3:59:42 PM3/7/14
to clo...@googlegroups.com
I have a web service that uses Korma for interacting with my db. To mock data for unit tests I want to re-bind korma.core/select to return known data and not hit a db.

Currently I have a db ns:

(nsservices.db
  (:require [korma.core :refer :all]
               [korma.db :refer :all]))

With a function 'func-select' that calls korma.core/select

And a test ns:

(ns ad-gallery-services.core-test
  (:require [clojure.test :refer :all]
            [ad-gallery-services.db :refer :all]
            [ad-gallery-services.web :refer :all]))

(deftest func-select-test
  (testing "Return nil if select returns empty"
    (with-redefs [korma.core/select (fn [& _] [])]
      (require 'ad-gallery-services.db :reload)
      (is (= (func-select 1)
             nil)))))

However, it keeps throwing the exception:

    ArityException Wrong number of args (1) passed to: core$where

Why is it even evaluating 'where', and (most importantly) how can I mock this data?

Alex Robbins

unread,
Mar 7, 2014, 4:12:26 PM3/7/14
to clo...@googlegroups.com
It looks like the issue is that korma.core/select is a macro, and has already expanded by the time you redef it.



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages