I've run into a problem using Midje autotest with protocols and records, when the protocols and records are defined in different files/namespaces.
I get an error like this:
FAIL at (core_test.clj:6)
Expected: 42
Actual: java.lang.IllegalArgumentException: No implementation of method: :f of protocol: #'midje-protocols-records-in-different-ns.protocol/P found for class: midje_protocols_records_in_different_ns.record.R
FAILURE: 1 check failed.
Here's a simple example that shows the problem...
My project structure is like this:
.
├── project.clj
├── src
│ └── midje_protocols_records_in_different_ns
│ ├── protocol.clj
│ └── record.clj
└── test
└── midje_protocols_records_in_different_ns
└── core_test.clj
My files are:
project.clj:
(defproject midje-protocols-records-in-different-ns "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:license {:name "Eclipse Public License"
:dependencies [[org.clojure/clojure "1.5.1"]])
protocol.clj:
(ns midje-protocols-records-in-different-ns.protocol)
(defprotocol P
(f [self]))
record.clj:
(ns midje-protocols-records-in-different-ns.record
(require [midje-protocols-records-in-different-ns.protocol
:refer [P]]))
(defrecord R
[]
P
(f [self] 42))
core_test.clj:
(ns midje-protocols-records-in-different-ns.core-test
(:use midje.sweet
midje-protocols-records-in-different-ns.protocol
midje-protocols-records-in-different-ns.record))
(fact (f (->R)) => 42)
Details of when the problem occurs:
- Only with autotest — non-auto testing works fine.
- Both "(autotest)" from nrepl and "lein midje :autotest" from the command line give the same problem.
- If I move the `defrecord` form from "record.clj" to "protocol.clj", there is no problem.
Any ideas?
Simon