Skip to content

Commit

Permalink
[Issue #82] now reports the first failure's normal report
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBaranosky committed Feb 19, 2012
1 parent e2ce67a commit 12b9205
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/midje/internal_ideas/report.clj
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
(indented (:stacktrace m))))

(defmethod report-strings :formula-fail [m]
(list "At least one run of your formula failed.")))
(report-strings (:first-failure m))))

(letfn [(render [m]
(->> m report-strings flatten (remove nil?) (map *renderer*) doall))]
Expand Down
10 changes: 6 additions & 4 deletions src/midje/unprocessed.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
[midje.internal-ideas.fact-context :only [nested-fact-description]]
midje.internal-ideas.report
midje.util.laziness
[midje.util.namespace :only [immigrate]]))
[midje.util.namespace :only [immigrate]]
[utilize.seq :only [find-first]]))
(immigrate 'midje.checkers)

(def ^{:private true} formula-reports (atom []))
Expand All @@ -20,9 +21,10 @@
(swap! formula-reports conj report-map))

(defn ^{:private true} report-formula-conclusion [report-map]
(let [all-report-maps (conj @formula-reports report-map)
result (if (every? #(= :pass (:type %)) all-report-maps) :pass :formula-fail)]
(report {:type result})
(let [all-report-maps (conj @formula-reports report-map)]
(if-let [failure (find-first #(not= :pass (:type %)) all-report-maps)]
(report {:type :formula-fail :first-failure failure})
(report {:type :pass}) )
(reset! formula-reports [])))

(letfn [(fail [type actual call]
Expand Down
14 changes: 13 additions & 1 deletion test/midje/internal_ideas/t_report.clj
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,16 @@
:expected "s"}
raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"a note"))
(nth raw-report 1) => #"a note"))

(fact "formula failures report about the supplied first-failure"
(let [failure-map {:type :formula-fail
:first-failure {:type :mock-expected-result-failure
:description "some description"
:position ["foo.clj" 3]
:actual nil
:expected "s"}}
raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"Expected: \"s\""
(nth raw-report 2) => #"Actual: nil"))
3 changes: 2 additions & 1 deletion test/midje/t_sweet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@
(after-silently
(formula [a "y"]
a => :foo))
(fact @reported => (one-of (contains {:type :formula-fail})))
(fact @reported => (one-of (contains {:type :formula-fail
:first-failure (contains {:type :mock-expected-result-failure})})))

(defn make-string []
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))
Expand Down

0 comments on commit 12b9205

Please sign in to comment.