Questions tagged [midje]

Midje is a unit test framework for Clojure.

60 questions
12
votes
4 answers

Clojure Unit testing : Check if a function was called

I'm trying to write some unit tests for my clojure function (I'm using clojure.test, but I can switch to midje if necessary). I have a function that reads like : (defn GenerateNodes [is-sky-blue? hot-outside? name] (cond (is-sky-blue?…
Attilah
  • 17,632
  • 38
  • 139
  • 202
8
votes
1 answer

How is 'provided' implemented in a fact in Midje?

I was reading Clojure in Action chapter 8 about TDD and experimented with the stubbing macro. It uses the dynamic binding mechanism to stub functions. Alas, in Clojure 1.3 it is not possible to use the binding mechanism for non-dynamic vars, so the…
Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
6
votes
0 answers

leiningen midje tests not working in Intellij

Consider the following (minimal) leiningen project ./project.clj: (defproject repro "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.5.1"] [midje "1.5.1"]]) ./repro/src/repro/core.clj: (ns…
Reb.Cabin
  • 5,426
  • 3
  • 35
  • 64
6
votes
2 answers

Why can't I use midje to mock a function that throws using slingshot's throw+

Here's the situation: I'm trying to unit test function A that calls function B. Function B is called in a slingshot try+ block and under certain circumstances it can throw using a slingshot throw+. I want to mock function B in a midje test so that…
Matt Daley
  • 458
  • 3
  • 15
4
votes
1 answer

reusing setup and teardown with against-background in midje

I have a number of midje facts that have setup/teardowns that are almost, but not quite, entirely the same. (against-background [(before :contents (setup!)) (before :contents (data)) (before :facts (set-access)) (after :contents (teardown!)] …
Toby Hede
  • 36,755
  • 28
  • 133
  • 162
4
votes
2 answers

Lein Midje :autotest throwing exception (No namespace found)

I am trying to setup autotest for midje. Currently, running lein midje works. However running lein midje :autottest gives me the stack trace below. I run through my different namespaces and they all compile Compiling 1 source files to…
oloo
  • 319
  • 2
  • 9
3
votes
2 answers

Midje on travis-ci fails with NoSuchMethodError: KeywordLookupSite.

I'm trying to use the Midje testing framework for Clojure on the Travis CI service. The project.clj looks like this: (defproject my-project "0.1.0-SNAPSHOT" :description "Example" :dependencies [[org.clojure/clojure "1.3.0"]] :dev-dependencies…
Christian Berg
  • 14,246
  • 9
  • 39
  • 44
3
votes
1 answer

Passing data to a liberator post endpoint in midje test using ring-mock

I am trying to write a midje test using ring-mock to do a post to a liberator endpoint. I can successfully write a test for get requests but I can't seem to pass data to the post, I only get back the malformed response. Here is the meat of the code…
user3509195
3
votes
1 answer

Using midje provided in a let clause doesn't stub methods

When I make a test using an outer let clause to structure some definitions and calls, the stubs don't work the way I'd expect. For example: This test fails (fact "blah" (let [x (meth1 123)] x => 246 (provided (meth2 123) =>…
aciniglio
  • 1,777
  • 1
  • 16
  • 18
3
votes
2 answers

Redefining a macro operation with Clojure + Midje

Background I'm new to Clojure so please forgive any glaring errors. I am trying to test some Clojure data access code that uses the redis-clojure library. Whilst my integration tests will, of course, test the full stack I do not want my unit tests…
jamiei
  • 2,006
  • 3
  • 20
  • 28
2
votes
1 answer

Hot to fix "WARNING: any? already refers to: #'clojure.core/any? in namespace: leiningen.midje, being replaced by: #'leiningen.midje/any?"

I'm try run tests in leiningen's compojure template (lein new compojure financeiro), using the midje framework and receive a warning: lein midje WARNING: any? already refers to: #'clojure.core/any? in namespace: leiningen.midje, being replaced by:…
Chinnon Santos
  • 413
  • 4
  • 11
2
votes
2 answers

How to test if key is UUID in clojure

I'm trying to check whether a keyword is an UUID. It should look like this (which is not working): {:70342332-7f99-417a-b864-9006de62ae05 {:a 1 b: 2}} => (just {uuid? {:a 1 :b 2}}) What are other ways to test it? Using Midje 1.9.
irios
  • 165
  • 1
  • 11
2
votes
1 answer

How to define prerequisite functions in Midje?

I should start by saying I'm new to Clojure, and FP in general. I've been reading the documentation about how to define prerequisites in Midje, but I can't make sense of some of it. My understanding was that to do top-down TDD, you're supposed to…
2
votes
1 answer

Midje fails on Macros in Clojure

Here is the passing version of the code: Normal function: That passes (defn my-fn [] (throw (IllegalStateException.))) (fact (my-fn) => (throws IllegalStateException)) Here is the macro version of it: (defmacro my-fn [] (throw…
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76
2
votes
2 answers

Testing Timbre log outputs with Midje

I am using Timbre as a logging library but I am having issues testing it with Midje. I've got the following method and all I'm trying to do is asserting that Will be printed is printed. (defn init [level] (timbre/merge-config! {:output-fn…
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
1
2 3 4