Skip to content
Browse files

Issue: #132 Delete examples.

  • Loading branch information...
1 parent b9b53c7 commit e7de9fc77c451366ca129fd76680aaad586a832d @marick committed Apr 27, 2012
Showing with 1 addition and 1,331 deletions.
  1. +1 −16 README.md
  2. +0 −28 examples/README
  3. +0 −9 examples/adder-webapp/README
  4. +0 −1 examples/adder-webapp/lein-expected-output
  5. +0 −14 examples/adder-webapp/project.clj
  6. +0 −5 examples/adder-webapp/public/adder.css
  7. +0 −5 examples/adder-webapp/script/run.clj
  8. +0 −75 examples/adder-webapp/src/adder/core.clj
  9. +0 −46 examples/adder-webapp/src/adder/middleware.clj
  10. +0 −32 examples/adder-webapp/test/adder/core_test.clj
  11. +0 −4 examples/basic/.gitignore
  12. +0 −85 examples/basic/README.html
  13. +0 −43 examples/basic/lein-expected-output
  14. +0 −16 examples/basic/make-run
  15. +0 −8 examples/basic/project.clj
  16. +0 −2 examples/basic/run
  17. +0 −48 examples/basic/run-expected-output
  18. +0 −235 examples/basic/test/basic/core_test.clj
  19. +0 −4 examples/compound-checkers/README
  20. +0 −43 examples/compound-checkers/lein-expected-output
  21. +0 −7 examples/compound-checkers/project.clj
  22. +0 −131 examples/compound-checkers/src/compound/two_finder.clj
  23. +0 −4 examples/leiningen-midje/.gitignore
  24. +0 −15 examples/leiningen-midje/README
  25. +0 −25 examples/leiningen-midje/lein-expected-output
  26. +0 −6 examples/leiningen-midje/project.clj
  27. +0 −5 examples/leiningen-midje/src/leiningen_midje/core.clj
  28. +0 −10 examples/leiningen-midje/src/leiningen_midje/embedded_facts.clj
  29. +0 −14 examples/leiningen-midje/test/leiningen_midje/t_core.clj
  30. +0 −5 examples/leiningen-test/README
  31. +0 −23 examples/leiningen-test/lein-expected-output
  32. +0 −5 examples/leiningen-test/project.clj
  33. +0 −1 examples/leiningen-test/src/lein_test/core.clj
  34. +0 −11 examples/leiningen-test/test/lein_test/test/deftest.clj
  35. +0 −8 examples/leiningen-test/test/lein_test/test/with_test.clj
  36. +0 −4 examples/semi-sweet-examples/.gitignore
  37. +0 −85 examples/semi-sweet-examples/README.html
  38. +0 −29 examples/semi-sweet-examples/lein-expected-output
  39. +0 −16 examples/semi-sweet-examples/make-run
  40. +0 −5 examples/semi-sweet-examples/project.clj
  41. +0 −2 examples/semi-sweet-examples/run
  42. +0 −36 examples/semi-sweet-examples/run-expected-output
  43. +0 −1 examples/semi-sweet-examples/src/semi_sweet_simple/core.clj
  44. +0 −164 examples/semi-sweet-examples/test/semi_sweet_simple/core_test.clj
View
17 README.md
@@ -53,23 +53,8 @@ list](http://groups.google.com/group/midje).
If you like videos of people programming, here's an
[8-minute infomercial](http://www.youtube.com/watch?v=a7YtkcIiLGI) that concentrates on transitioning from
clojure.test.
-If
-you like looking straight at code, [this heavily annotated
-example](http://github.com/marick/Midje/blob/master/examples/basic/test/basic/core_test.clj)
- has a bunch. If you want to run that example, you
- can download it:
-1. [Click here](http://github.com/marick/Midje/raw/master/downloads/examples.zip).
-2. In a shell, go to the directory your browser unpacked the example into. It should be named `examples`.
-3. Go to `examples/basic/`.
-4. Type "./run" or "lein test".
-5. The facts in `test/*/core_test.clj` will be checked.
-
-You can [download
-everything](http://github.com/marick/Midje/downloads) to get
-more examples.
-
-Or in the #midje channel on freenode!
+There is a #midje channel on freenode.
Contributors
==============
View
28 examples/README
@@ -1,28 +0,0 @@
-adder-webapp/
- Mark McGranaghan's "Developing and Deploying a Simple Clojure Web
- Application", converted to use Midje.
-
-basic/
- Various tests that show the use of Midje's default "sweet" interface.
-
-cake-midje/
- An example of running Midje tests with Cake.
-
-compound-checkers/
- Writing checkers that check more than one thing. (The
- tricky bit is getting the line numbers to come out
- right.)
-
-leiningen-midje/
- The Midje plugin for leiningen
-
-leiningen-test/
- You can use 'lein test'. You'll see all the individual
- failures from both midje and clojure.test, but the
- summary will be wrong.
-
-semi-sweet-examples/
- Midje's default "sweet" interface is built on top of a
- "semi-sweet" interface (which in turn is built on an
- "unprocessed" interface. These examples show how
- the semi-sweet interface is used.
View
9 examples/adder-webapp/README
@@ -1,9 +0,0 @@
-In this example, I've converted the tests from from Mark
-McGranaghan's "Developing and Deploying a Simple Clojure Web
-Application" to use Midje. I'm including them with his permission.
-
-http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html
-
-To run the tests, type:
-
-% lein midje
View
1 examples/adder-webapp/lein-expected-output
@@ -1 +0,0 @@
-All claimed facts (7) have been confirmed.
View
14 examples/adder-webapp/project.clj
@@ -1,14 +0,0 @@
-(defproject adder "0.4.0"
- :description "Add two numbers."
- :dependencies
- [[org.clojure/clojure "[1.2.0],[1.2.1],[1.3.0]"]
- [ring/ring "1.0.0-beta2"]
- [ring/ring-devel "1.0.0-beta2"]
- [ring/ring-jetty-adapter "1.0.0-beta2"]
- [compojure "0.6.5"]
- [hiccup "0.3.7"]]
- :dev-dependencies
- [[lein-run "1.0.0"]
- [lein-midje "[1.0.0,)"]
- [midje "1.3.2-SNAPSHOT"]
- ])
View
5 examples/adder-webapp/public/adder.css
@@ -1,5 +0,0 @@
-.math {
- font-family: Monaco, monospace; }
-
-.action {
- margin-top: 2em; }
View
5 examples/adder-webapp/script/run.clj
@@ -1,5 +0,0 @@
-(use 'ring.adapter.jetty)
-(require 'adder.core)
-
-(let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
- (run-jetty #'adder.core/app {:port port}))
View
75 examples/adder-webapp/src/adder/core.clj
@@ -1,75 +0,0 @@
-(ns adder.core
- (:use compojure.core)
- (:use hiccup.core)
- (:use hiccup.page-helpers)
- (:use ring.middleware.reload)
- (:use ring.util.response)
- (:use ring.middleware.stacktrace)
- (:use adder.middleware)
- (:use ring.middleware.file)
- (:use ring.middleware.file-info)
-)
-
-(defn view-layout [& content]
- (html
- (doctype :xhtml-strict)
- (xhtml-tag "en"
- [:head
- [:meta {:http-equiv "Content-type"
- :content "text/html; charset=utf-8"}]
- [:title "adder"]
- [:link {:href "/adder.css" :rel "stylesheet" :type "text/css"}]]
- [:body content])))
-
-(defn view-input [& [a b]]
- (view-layout
- [:h2 "add two numbers"]
- [:form {:method "post" :action "/"}
- (if (and a b)
- [:p "those are not both numbers!"])
- [:input.math {:type "text" :name "a" :value a}] [:span.math " + "]
- [:input.math {:type "text" :name "b" :value b}] [:br]
- [:input.action {:type "submit" :value "add"}]]))
-
-(defn view-output [a b sum]
- (view-layout
- [:h2 "two numbers added"]
- [:p.math a " + " b " = " sum]
- [:a.action {:href "/"} "add more numbers"]))
-
-(defn parse-input [a b]
- [(Integer/parseInt a) (Integer/parseInt b)])
-
-(defroutes handler
- (GET "/" []
- (view-input))
-
- (POST "/" [a b]
- (try
- (let [[a b] (parse-input a b)
- sum (+ a b)]
- (view-output a b sum))
- (catch NumberFormatException e
- (view-input a b))))
-
- (ANY "/*" [path]
- (redirect "/"))
-)
-
-
-(def production?
- (= "production" (get (System/getenv) "APP_ENV")))
-
-(def development?
- (not production?))
-
-(def app
- (-> #'handler
- (wrap-file "public")
- (wrap-file-info)
- (wrap-request-logging)
- (wrap-if development? wrap-reload '[adder.middleware adder.core])
- (wrap-bounce-favicon)
- (wrap-exception-logging)
- (wrap-if production? wrap-failsafe)
- (wrap-if development? wrap-stacktrace)))
View
46 examples/adder-webapp/src/adder/middleware.clj
@@ -1,46 +0,0 @@
-(ns adder.middleware
- (:require [clj-stacktrace.repl :as strp])
-)
-
-(letfn [(log [msg & vals]
- (let [line (apply format msg vals)]
- (locking System/out (println line))))]
-
- (defn wrap-request-logging [handler]
- (fn [{:keys [request-method uri] :as req}]
- (let [start (System/currentTimeMillis)
- resp (handler req)
- finish (System/currentTimeMillis)
- total (- finish start)]
- (log "request %s %s (%dms)" request-method uri total)
- resp)))
-
- (defn wrap-exception-logging [handler]
- (fn [req]
- (try
- (handler req)
- (catch Exception e
- (log "Exception:\n%s" (strp/pst-str e))
- (throw e))))))
-
-(defn wrap-bounce-favicon [handler]
- (fn [req]
- (if (= [:get "/favicon.ico"] [(:request-method req) (:uri req)])
- {:status 404
- :headers {}
- :body ""}
- (handler req))))
-
-(defn wrap-if [handler pred wrapper & args]
- (if pred
- (apply wrapper handler args)
- handler))
-
-(defn wrap-failsafe [handler]
- (fn [req]
- (try
- (handler req)
- (catch Exception e
- {:status 500
- :headers {"Content-Type" "text/plain"}
- :body "We're sorry, something went wrong."}))))
View
32 examples/adder-webapp/test/adder/core_test.clj
@@ -1,32 +0,0 @@
-(ns adder.core-test
- (:use midje.sweet)
- (:use adder.core))
-
-(facts "about utilities"
- "parse-input"
- (parse-input "1" "2") => [1 2]
- (parse-input "foo" "2") => (throws NumberFormatException)
-
- "view-output"
- (view-output 1 2 3) => (contains #"two numbers added"))
-
-(facts "about the main page"
- "Bare request produces prompt"
- (handler {:uri "/" :request-method :get})
- => (contains {:status 200
- :body #"add two numbers"})
-
- "Valid numbers produce sum"
- (handler {:uri "/" :request-method :post :params {"a" "1" "b" "2"}})
- => (contains {:status 200
- :body #"1 \+ 2 = 3"})
-
- "Non-numbers produce error message"
- (handler {:uri "/" :request-method :post :params {"a" "2" "b" "f"}})
- => (contains {:status 200
- :body #"those are not both numbers"}))
-
-(fact "Other pages produce redirect"
- (handler {:uri "/anything" :request-method :get})
- => (contains {:status 302,
- :headers (contains {"Location" "/"})}))
View
4 examples/basic/.gitignore
@@ -1,4 +0,0 @@
-pom.xml
-*jar
-lib
-classes
View
85 examples/basic/README.html
@@ -1,85 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
-<html> <head>
-<title>Sweet Example - Basic</title>
-</head>
-
-<body>
-
-<p>
-Did you download the zip or tar file described as the
-easiest way to try out Midje?
-</p>
-
-<ul>
- <li><b>Yes!</b>
- <p>
- If you're on Unix (including the Mac), the shell script <code>run</code> runs the tests:
- </p>
-
- <pre>
- % run
- </pre>
-
- <p>
- If you're on Windows, you can look at the contents of the
- script (two lines) and translate them into Windows terms.
- </p>
-
- <p>
- The file in this folder called
- <code>run-expected-output</code> shows what
- the results should look like.
- </p>
- </li>
-
-
-
-
-<li><b>No.</b>
-
-<p>
-<ol>
- <li>
- <p>
- You must have Leiningen installed to follow these
- instructions. It's easy to install. <a href="http://github.com/technomancy/leiningen/blob/master/README.md">Start here.</a>
-
- </p>
- </li>
- <li>
- <p>
- To download and install everything you need to
- run the example, including Midje, type this:
- </p>
- <pre>
- % lein deps
- </pre>
- <p>
- The downloaded jar files are put in the
- <code>lib/</code> subdirectory.
- </p>
- </li>
-
- <li>
- <p>
- The file
- <code>test/basic/core_test.clj</code> is
- intended to be good documentation of the different ways
- you can use <code>midje.sweet</code>. You can run
- the tests like this:
- </p>
- <pre>
- % lein midje
- </pre>
- <p>
- The file in this directory called
- <code>lein-expected-output</code> shows what
- the results should look like.
- </p>
- </li>
-</ol>
-
-</li>
-</ul>
-
-</body> </html>
View
43 examples/basic/lein-expected-output
@@ -1,43 +0,0 @@
-
-FAIL at (core_test.clj:34)
- Expected: 3
- Actual: 4
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:45)
-Actual result did not agree with the checking function.
- Actual result: 4
- Checking function: odd?
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:80)
-Actual result did not agree with the checking function.
- Actual result: [3 3 1 2]
- Checking function: (just [1 2 3] :in-any-order)
- The checker said this about the reason:
- Expected three elements. There were four.
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:130)
-These calls were not made the right number of times:
- (alive? ...cell...) [expected at least once, actually never called]
-
-FAIL at (core_test.clj:131)
-These calls were not made the right number of times:
- (neighbor-count ...cell...) [expected at least once, actually never called]
-
-FAIL at (core_test.clj:128)
-Actual result did not agree with the checking function.
- Actual result: nil
- Checking function: truthy
-^^^^ The previous three failures were expected ^^^^
-
-FAIL at (core_test.clj:231)
-These calls were not made the right number of times:
- (property-of ...data-structure-value-1...) [expected at least once, actually never called]
-
-FAIL at (core_test.clj:231)
-These calls were not made the right number of times:
- (data-structure) [expected at least once, actually never called]
-^^^^ The previous two failures were expected ^^^^
-FAILURE: 8 facts were not confirmed. (But 14 were.)
View
16 examples/basic/make-run
@@ -1,16 +0,0 @@
-#!/usr/bin/env ruby
-# Yeah, I know, I should use Clojure.
-
-Dir.chdir "test"
-jars=Dir.glob('../lib/*')+Dir.glob('../lib/dev/*')
-classpath=jars.join(':')
-clojure = %q{(ns basic.core-test)(run-tests)}
-command="java -cp #{classpath} clojure.main -i basic/core_test.clj -e '#{clojure}'"
-Dir.chdir ".."
-
-File.open("run", "w") do | io |
- io.puts "cd test"
- io.puts command
-end
-
-File.chmod(0777, "run")
View
8 examples/basic/project.clj
@@ -1,8 +0,0 @@
-(defproject basic "1.0.0"
- :description "An example of using Midje's sweet interface"
- :dependencies [[org.clojure/clojure "[1.2.0,1.2.1]"]
- [org.clojure/clojure-contrib "[1.2.0,1.2.1]"]
- ]
- :dev-dependencies [[midje "1.3.2-SNAPSHOT"]
- [lein-midje "[1.0.0,)"]])
-
View
2 examples/basic/run
@@ -1,2 +0,0 @@
-cd test
-java -cp ../lib/clojure-1.2.1.jar:../lib/clojure-contrib-1.2.0.jar:../lib/dev:../lib/dev/algo.monads-0.1.0.jar:../lib/dev/colorize-0.1.1.jar:../lib/dev/core.incubator-0.1.0.jar:../lib/dev/core.logic-0.6.5.jar:../lib/dev/core.match-0.2.0-alpha9.jar:../lib/dev/core.unify-0.5.2.jar:../lib/dev/joda-time-2.0.jar:../lib/dev/math.combinatorics-0.0.1.jar:../lib/dev/midje-1.3.2-SNAPSHOT.jar:../lib/dev/ordered-1.1.0.jar:../lib/dev/tools.macro-0.1.1.jar:../lib/dev/utilize-0.2.3.jar clojure.main -i basic/core_test.clj -e '(ns basic.core-test)(run-tests)'
View
48 examples/basic/run-expected-output
@@ -1,48 +0,0 @@
-
-FAIL at (core_test.clj:34)
- Expected: 3
- Actual: 4
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:45)
-Actual result did not agree with the checking function.
- Actual result: 4
- Checking function: odd?
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:80)
-Actual result did not agree with the checking function.
- Actual result: [3 3 1 2]
- Checking function: (just [1 2 3] :in-any-order)
- The checker said this about the reason:
- Expected three elements. There were four.
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:130)
-These calls were not made the right number of times:
- (alive? ...cell...) [expected at least once, actually never called]
-
-FAIL at (core_test.clj:131)
-These calls were not made the right number of times:
- (neighbor-count ...cell...) [expected at least once, actually never called]
-
-FAIL at (core_test.clj:128)
-Actual result did not agree with the checking function.
- Actual result: nil
- Checking function: truthy
-^^^^ The previous three failures were expected ^^^^
-
-FAIL at (core_test.clj:231)
-These calls were not made the right number of times:
- (property-of ...data-structure-value-1...) [expected at least once, actually never called]
-
-FAIL at (core_test.clj:231)
-These calls were not made the right number of times:
- (data-structure) [expected at least once, actually never called]
-^^^^ The previous two failures were expected ^^^^
-
-Testing basic.core-test
-
-Ran 0 tests containing 0 assertions.
-0 failures, 0 errors.
-{:type :summary, :pass 0, :test 0, :error 0, :fail 0}
View
235 examples/basic/test/basic/core_test.clj
@@ -1,235 +0,0 @@
-(ns basic.core-test
- (:use clojure.test)
- (:use midje.sweet)
-)
-
-(defn note-expected-failure [] (println "^^^^ The previous failure was expected ^^^^"))
-
- ;;;
-
-;; This is an example of the Midje version of a clojure.test test that would
-;; look like this:
-;; (is (= (+ 1 1) 2))
-;; In Midje's preferred metaphor, such statements are facts about the
-;; world, so its version looks like this:
-
-(fact (+ 1 1) => 2)
-
-;; You can have multiple assertions within the fact form. The function
-;; has an alias, facts, for those of you who are sticklers about
-;; grammar:
-
-(facts "arithmetic"
- (+ 1 1) => 2
- (+ 1 0) => 1)
-
-;; Notice also that you can add "doc strings" to facts.
-
-;; Failing tests should look familiar:
-;; FAIL at (core_test.clj:34)
-;; Expected: 3
-;; Actual: 4
-
-(fact ( #(+ 1 %) 3) => 3) (note-expected-failure)
-
-;; You can use clojure.test to wrap facts in deftest.
-;; See the examples/sweet-examples/leiningen-test example and
-;; http://github.com/marick/Midje/wiki/Lein-test
-;; In this example, I don't wrap facts. Instead, I use Midje's
-;; leiningen plugin or run the tests directly.
-
-;; If the right-hand side of an arrow is a function, the actual result
-;; is passed as the function's single argument.
-
-(fact ( #(+ 1 %) 3) => odd?) (note-expected-failure)
-;; The failing test will look slightly different:
-;; FAIL at (core_test.clj:45)
-;; Actual result did not agree with the checking function.
-;; Actual result: 4
-;; Checking function: odd?
-
-
-;; If you're testing something that produces a function, use
-;; (exactly):
-;(fact (first [even? odd?]) => (exactly odd?)) (note-expected-failure)
-
-;; NOTE: the previous line is commented out because Midje prints the
-;; function name nicely in Clojure 1.2. A breaking change to Clojure
-;; 1.3 makes it harder to accomplish this, so an ugly name that
-;; can vary between runs is printed instead. Leaving that name in the
-;; output would prevent this from being used as part of the
-;; just-before-release regression test suite.
-
-;; FAIL at (core_test.clj:56)
-;; Actual result did not agree with the checking function.
-;; Actual result: a function named 'even?'
-;; Checking function: (exactly odd?)
-
-;; (Midje can't always determine the name of the function. If not, it'll print
-;; gobbledeegook like #<core$even_QMARK_ clojure.core$even_QMARK_@21a722ef>.)
-
-;; There are a number of matching functions available. You can find them all with
-;; (ns-publics 'midje.checkers)
-;; They have doc strings.
-;; (Or you can look at the wiki: http://github.com/marick/Midje/wiki/Checkers)
-;; Here's one of them:
-
-(fact
- [3 1 2] => (just [1 2 3] :in-any-order) ;; succeeds
- [3 3 1 2] => (just [1 2 3] :in-any-order)) (note-expected-failure)
-;; FAIL at (core_test.clj:74)
-;; Actual result did not agree with the checking function.
-;; Actual result: [3 3 1 2]
-;; Checking function: (just [1 2 3] :in-any-order)
-;; The checker said this about the reason:
-;; Expected three elements. There were four.
-
-;; You can negate the sense of a check:
-
-(fact (set [1 2 3]) =not=> sequential?)
-
-;; Facts work with variables bound both within and outside of the fact form:
-(let [a 3]
- (fact (+ a a) => 6)
- (fact (let [b 33]
- (+ a b) => 36)))
-
-;; Sometimes facts are only true provided other facts are true. Midje
-;; has a notation for that. Suppose we're testing the rules for
-;; Conway's Life (as used in Corey Haines' Code Retreat workshops). In
-;; it, a cell "comes to life" if it is dead but has three living
-;; neighbors. Let's say that rule will be part of an
-;; alive-in-next-generation? function. As normal, we have to declare
-;; that function before using it in a fact:
-
-(defn alive-in-next-generation? [cell]
- ; not started yet.
-)
-
-;; As we write the fact, we'll decide on prerequisite facts, which are
-;; themselves functions that need to be declared. We could use the
-;; Clojure's `declare` macro, but I prefer this one:
-
-(unfinished alive? neighbor-count)
-
-;; It makes it a little clearer what role those vars are playing, and
-;; it defines the functions to blow up informatively if they're ever
-;; called. Also, the Midje source contains an Emacs minor mode to make
-;; it more convenient to write facts and add prerequisites to the
-;; unfinished list. See
-;; http://github.com/marick/Midje/wiki/Midje-mode
-
-;; All that given, here's an expression of the rule that lets you get the
-;; logic of alive-in-next-generation? right before fussing with
-;; counting neighbor cells:
-
-(fact
- (alive-in-next-generation? ...cell...) => truthy
- (provided
- (alive? ...cell...) => false
- (neighbor-count ...cell...) => 3))
-(println "^^^^ The previous three failures were expected ^^^^")
-
-;; Notes:
-;; ...cell... : I use this shorthand to represent some
-;; random value. None of its characteristics
-;; matter except those defined by prerequisites.
-;; You don't have to define such "metaconstants" -
-;; Midje does it for you.
-;;
-;; truthy : Truthy is another one of Midje's checking
-;; functions. It accepts any value other than
-;; false or nil.
-;;
-;; provided : Provided gives a list of prerequisites the original
-;; fact depends upon. (Note that the "provided"
-;; form isn't within the original claim, but follows
-;; just after it.)
-
-;; When the fact is checked, it will fail like this:
-
-;; FAIL for (core_test.clj:120)
-;; You claimed the following was needed, but it was never used:
-;; (alive? ...cell...)
-;; FAIL for (core_test.clj:121)
-;; You claimed the following was needed, but it was never used:
-;; (neighbor-count ...cell...)
-;; FAIL at (core_test.clj:118)
-;; Actual result did not agree with the checking function.
-;; Actual result: nil
-;; Checking function: truthy
-
-
-;; You can mention a particular unimplemented function more than once,
-;; giving it a different argument each time:
-
-(unfinished g)
-
-(defn g-adder [n1 n2]
- (+ (g n1) (g n2)))
-
-(fact
- (g-adder 2 3) => 11
- (provided
- (g 2) => 4
- (g 3) => 7))
-
-;; When looking for a matching prerequisite, Midje 1.1 uses the same rules as
-;; when checking a function-under-test's actual result. Because that's
-;; been found to be confusing, it'll change. What follows is future-proof
-;; test-writing.
-
-(unfinished subfunction)
-
-(defn function-under-test [value-to-pass]
- (subfunction value-to-pass))
-
-(facts "about functions in the argument list of a prerequisite"
- "Ordinarily, functions in an argument list have to be matched exactly"
- (function-under-test odd?) => 11
- (provided (subfunction odd?) => 11)
-
- "If you want to use an ordinary function as a checker, wrap it in as-checker."
- (function-under-test 3) => 11
- (provided (subfunction (as-checker odd?)) => 11)
-
- "Predefined checkers can be used unadorned"
- (function-under-test 'blue-cow) => 11
- (provided (subfunction anything) => 11)
-
- (function-under-test 3.00000001) => 11
- (provided (subfunction (roughly 3.0)) => 11))
-
-;; The return values of a prerequisite function don't follow the rules
-;; for arguments. They're literal constant values.
-
-;; I often find myself with one prerequisite that returns a data structure
-;; that's immediately given to another oaliasne. That would look like this:
-
-(unfinished property-of data-structure)
-(defn function-under-test []
- (property-of (data-structure)))
-
-(fact
- (function-under-test) => 3
- (provided
- (data-structure) => ...data-structure...
- (property-of ...data-structure...) => 3))
-
-;; I'd use a metaconstant for the data structure because I don't care to
-;; commit myself to an exact format yet.
-;;
-;; Because this form is so common, you're allowed to "fold" the two
-;; prerequisites together:
-
-(defn function-under-test [] 3) ; so we get failures.
-
-(fact
- (function-under-test) => 3
- (provided
- (property-of (data-structure)) => 3))
-(println "^^^^ The previous two failures were expected ^^^^")
-
-;; Notice that one of the failures refers to a generated metaconstant,
-;; ...data-structure-value-1...
-
View
4 examples/compound-checkers/README
@@ -1,4 +0,0 @@
-Different ways of creating checkers that check more than one
-thing.
-
-The tests are with the source in src/compound/two_finder.clj
View
43 examples/compound-checkers/lein-expected-output
@@ -1,43 +0,0 @@
-
-FAIL at (two_finder.clj:35)
-Actual result did not agree with the checking function.
- Actual result: ["SO WRONG!"]
- Checking function: (finds [1 3])
-
-FAIL at (two_finder.clj:36)
-Actual result did not agree with the checking function.
- Actual result: (1 3)
- Checking function: (finds [1 3])
-
-FAIL at (two_finder.clj:58)
-Actual result did not agree with the checking function.
- Actual result: ["SO WRONG!"]
- Checking function: (finds [1 3])
- During checking, these intermediate values were seen:
- (= actual expected) => false
- (= (clojure.core/deref count-atom) (count expected)) => true
-
-FAIL at (two_finder.clj:59)
-Actual result did not agree with the checking function.
- Actual result: (1 3)
- Checking function: (finds [1 3])
- During checking, these intermediate values were seen:
- (= actual expected) => true
- (= (clojure.core/deref count-atom) (count expected)) => false
-
-FAIL at (two_finder.clj:99)
- Expected: [1 3]
- Actual: ["SO WRONG!"]
-
-FAIL at (two_finder.clj:100)
- Expected: 2
- Actual: 900
-
-FAIL at (two_finder.clj:126)
- Expected: [111 333]
- Actual: ["SO WRONG!"]
-
-FAIL at (two_finder.clj:127)
- Expected: 2
- Actual: 900
-FAILURE: 8 facts were not confirmed. (But 8 were.)
View
7 examples/compound-checkers/project.clj
@@ -1,7 +0,0 @@
-(defproject compound "0.4.0"
- :description "Compound checker"
- :dependencies
- [[org.clojure/clojure "[1.2.0,1.2.1]"]
- [org.clojure/clojure-contrib "1.2.0"]]
- :dev-dependencies [[midje "1.3.2-SNAPSHOT"]
- [lein-midje "[1.0.0,)"]])
View
131 examples/compound-checkers/src/compound/two_finder.clj
@@ -1,131 +0,0 @@
-(ns compound.two-finder
- (use midje.sweet))
-
-;;Source
-
-(def count-atom (atom 0))
-
-(defn two-finder
- "filters N elements in input collection and sets count-atom to number found"
- [pred coll]
- (let [filtered (filter pred coll)]
- (swap! count-atom (constantly (count filtered)))
- filtered))
-
-(defn two-finder-bad-list [pred coll]
- (let [filtered (filter pred coll)]
- (swap! count-atom (constantly (count filtered)))
- ["SO WRONG!"]))
-
-(defn two-finder-bad-atom [pred coll]
- [pred coll]
- (let [filtered (filter pred coll)]
- (swap! count-atom (constantly 900))
- filtered))
-
-
-;;Simple function - easy, but not recommended
-
-(defn finds [expected]
- (fn [actual]
- (and (= actual expected)
- (= @count-atom (count expected)))))
-
-(fact
- (two-finder-bad-list odd? [1 2 3]) => (finds [1 3])
- (two-finder-bad-atom odd? [1 2 3]) => (finds [1 3]))
-
-;; Virtues:
-;; * Easy to remember how to do it.
-
-;; Flaws:
-;; * You only find out that something failed, not which check:
-;; Actual result: (1 3)
-;; Checking function: (finds [1 3])
-;; At first glance, the above surely looks as if it should succeed.
-
-
-;; Chatty checkers
-
-;; Easy to create by changing the 'fn' to chatty-checker:
-
-(defn finds [expected]
- (chatty-checker [actual]
- (and (= actual expected)
- (= @count-atom (count expected)))))
-
-(fact
- (two-finder-bad-list odd? [1 2 3]) => (finds [1 3])
- (two-finder-bad-atom odd? [1 2 3]) => (finds [1 3]))
-
-;; Virtues:
-;; * Tells you intermediate results:
-;; FAIL at (two_finder.clj:56)
-;; Actual result did not agree with the checking function.
-;; Actual result: (1 3)
-;; Checking function: (finds [1 3])
-;; During checking, these intermediate values were seen:
-;; (= actual expected) => true
-;; (= (clojure.core/deref count-atom) (count expected)) => false
-
-;; Flaws:
-;; * Chatty checkers currently don't obey short-circuiting AND,
-;; so second check will be evaluated even if first was false.
-;; * More verbose output.
-;; * Only works if the checks you're interested fit into a simple form:
-;; (f ..check.. ..check..)
-
-
-
-;;A macro containing expects
-
-;; #'fact is a macro that expands out into a "semi-sweet" macro named
-;; #'expect. You can use #'expect directly:
-
-(defmacro finds [expected]
- `(fn [actual#]
- (and (expect actual# => ~expected)
- (expect @count-atom => (count ~expected)))
- true))
-
-;; Explanation:
-;; * You have to use a macro so that line numbers can be found correctly.
-;; * Because expect returns false if the check fails, you can avoid
-;; redundant checks.
-;; * The ending true is to that a failure isn't forwarded on to the check
-;; in the calling form.
-
-(fact
- (two-finder-bad-list odd? [1 2 3]) => (finds [1 3])
- (two-finder-bad-atom odd? [1 2 3]) => (finds [1 3]))
-
-;; Virtues:
-;; * Terser output than chatty-checkers and works when they don't.
-
-;; Flaws:
-;; * It messes up totals. For example, the second check above looks
-;; like one check that fails, but it's actually two succeeding
-;; checks and one failing. (There are two checks within the macro
-;; and one outside. The one outside will always succeed - it's really
-;; there only for decoration.
-;; * Harder to remember how to make it.
-
-
-;; One final stylistic point
-
-;; The various versions of #'finds say nothing to the reader about the
-;; count, so this is probably preferable:
-
-(defmacro finds [expected-coll _ expected-count]
- `(fn [actual#]
- (and (expect actual# => ~expected-coll)
- (expect @count-atom => ~expected-count))
- true))
-
-(fact
- (two-finder-bad-list odd? [111 222 333]) => (finds [111 333] :stashes 2)
- (two-finder-bad-atom odd? [111 222 333]) => (finds [111 333] :stashes 2))
-
-;; Notice that I also changed the numbers in the list to avoid a
-;; misinterpretation like "Ah, it stashes the number (numbers?) that
-;; were excluded from the result."
View
4 examples/leiningen-midje/.gitignore
@@ -1,4 +0,0 @@
-pom.xml
-*jar
-lib
-classes
View
15 examples/leiningen-midje/README
@@ -1,15 +0,0 @@
-This shows the use of a Midje plugin for Leiningen. It's in
-the file leiningen/midje.clj
-
-You run it like this:
-
-% lein midje
-
-As with `lein test`, you can give namespace arguments to
-check only particular namespaces.
-
-`lein midje` checks both the `test` and `src` directories.
-
-It will also run clojure.test deftests if any exist.
-
-
View
25 examples/leiningen-midje/lein-expected-output
@@ -1,25 +0,0 @@
-The following two failures are intentional.
-
-FAIL at (t_core.clj:10)
-These calls were not made the right number of times:
- (g 1) [expected at least once, actually never called]
-
-FAIL at (t_core.clj:8)
- Expected: 1
- Actual: nil
-
-FAIL at (embedded_facts.clj:10)
- Expected: 2
- Actual: 1
-The following failure (from deftest) is intentional.
->>> Output from clojure.test tests:
-
-FAIL in (a-failing-test) (t_core.clj:14)
-expected: (= 33 (+ 1 2))
- actual: (not (= 33 3))
-
->>> clojure.test summary:
-Ran 1 tests containing 1 assertions.
-1 failures, 0 errors.
->>> Midje summary:
-FAILURE: 3 facts were not confirmed. (But 1 was.)
View
6 examples/leiningen-midje/project.clj
@@ -1,6 +0,0 @@
-(defproject leiningen-midje "1.0.0-SNAPSHOT"
- :description "FIXME: write"
- :dependencies [[org.clojure/clojure "[1.2.0,1.2.1]"]
- [org.clojure/clojure-contrib "1.2.0"]]
- :dev-dependencies [[midje "1.3.2-SNAPSHOT"]
- [lein-midje "[1.0.0,)"]])
View
5 examples/leiningen-midje/src/leiningen_midje/core.clj
@@ -1,5 +0,0 @@
-(ns leiningen-midje.core)
-
-(defn g [n])
-
-(defn f [n])
View
10 examples/leiningen-midje/src/leiningen_midje/embedded_facts.clj
@@ -1,10 +0,0 @@
-(ns leiningen-midje.embedded-facts
- [:use [midje.sweet]])
-
-
-(defn embedded [n] 1)
-
-
-(facts
- (embedded 1) => 1
- (embedded 2) => 2)
View
14 examples/leiningen-midje/test/leiningen_midje/t_core.clj
@@ -1,14 +0,0 @@
-(ns leiningen-midje.t-core
- (:use leiningen-midje.core
- clojure.test
- midje.sweet))
-
-(println "The following two failures are intentional.")
-(fact
- (f 1) => 1
- (provided
- (g 1) => 1))
-
-(deftest a-failing-test
- (println "The following failure (from deftest) is intentional.")
- (is (= 33 (+ 1 2))))
View
5 examples/leiningen-test/README
@@ -1,5 +0,0 @@
-This shows how to use Midje so that "lein test" prints
-something useful.
-
-Look in the test directory to see how tests are set up.
-
View
23 examples/leiningen-test/lein-expected-output
@@ -1,23 +0,0 @@
-
-Testing lein-test.test.deftest
-
-FAIL at (deftest.clj:10)
- Expected: 4
- Actual: 3
-
-FAIL at (deftest.clj:11)
- Expected: 4
- Actual: 5
-
-FAIL at (deftest.clj:7)
- Expected: 3
- Actual: 2
-
-Testing lein-test.test.with-test
-
-FAIL at (with_test.clj:8)
- Expected: 3
- Actual: 2
-
-Ran 3 tests containing 4 assertions.
-4 failures, 0 errors.
View
5 examples/leiningen-test/project.clj
@@ -1,5 +0,0 @@
-(defproject lein-test "1.0.0-SNAPSHOT"
- :description "FIXME: write"
- :dependencies [[org.clojure/clojure "[1.2.0,1.2.1]"]
- [org.clojure/clojure-contrib "1.2.0"]]
- :dev-dependencies [[midje "1.3.2-SNAPSHOT"]])
View
1 examples/leiningen-test/src/lein_test/core.clj
@@ -1 +0,0 @@
-(ns lein-test.core)
View
11 examples/leiningen-test/test/lein_test/test/deftest.clj
@@ -1,11 +0,0 @@
-(ns lein-test.test.deftest
- (:use [lein-test.core] :reload)
- (:use [midje.sweet]
- [clojure.test]))
-
-(deftest one-fact-in-a-test
- (fact (+ 1 1) => 3))
-
-(deftest two-facts-in-a-test
- (fact (+ 1 2) => 4)
- (fact (+ 2 3) => 4))
View
8 examples/leiningen-test/test/lein_test/test/with_test.clj
@@ -1,8 +0,0 @@
-(ns lein-test.test.with-test
- (:use [lein-test.core] :reload)
- (:use [clojure.test]
- [midje.sweet]))
-
-(with-test
- (defn foo [x y] (* x y))
- (fact (foo 1 2) => 3))
View
4 examples/semi-sweet-examples/.gitignore
@@ -1,4 +0,0 @@
-pom.xml
-*jar
-lib
-classes
View
85 examples/semi-sweet-examples/README.html
@@ -1,85 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
-<html> <head>
-<title>Semi-Sweet Example - Simple</title>
-</head>
-
-<body>
-
-<p>
-Did you download the zip or tar file described as the
-easiest way to try out Midje?
-</p>
-
-<ul>
- <li><b>Yes!</b>
- <p>
- If you're on Unix (including the Mac), the shell script <code>run</code> runs the tests:
- </p>
-
- <pre>
- % run
- </pre>
-
- <p>
- If you're on Windows, you can look at the contents of the
- script (two lines) and translate them into Windows terms.
- </p>
-
- <p>
- The file in this folder called
- <code>run-expected-output</code> shows what
- the results should look like.
- </p>
- </li>
-
-
-
-
-<li><b>No.</b>
-
-<p>
-<ol>
- <li>
- <p>
- You must have Leiningen installed to follow these
- instructions. It's easy to install. <a href="http://github.com/technomancy/leiningen/blob/master/README.md">Start here.</a>
-
- </p>
- </li>
- <li>
- <p>
- To download and install everything you need to
- run the example, including Midje, type this:
- </p>
- <pre>
- % lein deps
- </pre>
- <p>
- The downloaded jar files are put in the
- <code>lib/</code> subdirectory.
- </p>
- </li>
-
- <li>
- <p>
- The file
- <code>test/semi_sweet_simple/core_test.clj</code> is
- intended to be good documentation of the different ways
- you can use <code>midje.semi-sweet</code>. You can run
- the tests like this:
- </p>
- <pre>
- % lein test
- </pre>
- <p>
- The file in this directory called
- <code>lein-expected-output</code> shows what
- the results should look like.
- </p>
- </li>
-</ol>
-
-</li>
-</ul>
-
-</body> </html>
View
29 examples/semi-sweet-examples/lein-expected-output
@@ -1,29 +0,0 @@
-
-Testing semi-sweet-simple.core-test
-
-FAIL at (core_test.clj:25)
- Expected: 3
- Actual: 4
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:30)
-Actual result did not agree with the checking function.
- Actual result: 4
- Checking function: odd?
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:43)
-Actual result did not agree with the checking function.
- Actual result: [3 3 1 2]
- Checking function: (just [1 2 3] :in-any-order)
- The checker said this about the reason:
- Expected three elements. There were four.
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:70)
-These calls were not made the right number of times:
- (first-fake 3) [expected at least once, actually never called]
-^^^^ The previous failure was expected ^^^^
-
-Ran 10 tests containing 16 assertions.
-4 failures, 0 errors.
View
16 examples/semi-sweet-examples/make-run
@@ -1,16 +0,0 @@
-#!/usr/bin/env ruby
-# Yeah, I know, I should use Clojure.
-
-Dir.chdir "test"
-jars=Dir.glob('../lib/*')+Dir.glob('../lib/dev/*')
-classpath=jars.join(':')
-clojure = %q{(ns semi-sweet-simple.core-test)(run-tests)}
-command="java -cp #{classpath} clojure.main -i semi_sweet_simple/core_test.clj -e '#{clojure}'"
-Dir.chdir ".."
-
-File.open("run", "w") do | io |
- io.puts "cd test"
- io.puts command
-end
-
-File.chmod(0777, "run")
View
5 examples/semi-sweet-examples/project.clj
@@ -1,5 +0,0 @@
-(defproject semi-sweet-simple "1.0.0"
- :description "An example of using Midje semi-sweet mocking"
- :dependencies [[org.clojure/clojure "[1.2.0,1.2.1]"]
- [org.clojure/clojure-contrib "1.2.0"]]
- :dev-dependencies [[midje "1.3.2-SNAPSHOT"]])
View
2 examples/semi-sweet-examples/run
@@ -1,2 +0,0 @@
-cd test
-java -cp ../lib/clojure-1.2.1.jar:../lib/clojure-contrib-1.2.0.jar:../lib/dev:../lib/dev/algo.monads-0.1.0.jar:../lib/dev/colorize-0.1.1.jar:../lib/dev/core.incubator-0.1.0.jar:../lib/dev/core.logic-0.6.5.jar:../lib/dev/core.match-0.2.0-alpha9.jar:../lib/dev/core.unify-0.5.2.jar:../lib/dev/joda-time-2.0.jar:../lib/dev/math.combinatorics-0.0.1.jar:../lib/dev/midje-1.3.2-SNAPSHOT.jar:../lib/dev/ordered-1.1.0.jar:../lib/dev/tools.macro-0.1.1.jar:../lib/dev/utilize-0.2.3.jar clojure.main -i semi_sweet_simple/core_test.clj -e '(ns semi-sweet-simple.core-test)(run-tests)'
View
36 examples/semi-sweet-examples/run-expected-output
@@ -1,36 +0,0 @@
-
-Testing semi-sweet-simple.core-test
-
-FAIL at (core_test.clj:25)
- Expected: 3
- Actual: 4
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:30)
-Actual result did not agree with the checking function.
- Actual result: 4
- Checking function: odd?
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:40)
-Actual result did not agree with the checking function.
- Actual result: a function named 'even?'
- Checking function: (exactly odd?)
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:51)
-Actual result did not agree with the checking function.
- Actual result: [3 3 1 2]
- Checking function: (just [1 2 3] :in-any-order)
- The checker said this about the reason:
- Expected three elements. There were four.
-^^^^ The previous failure was expected ^^^^
-
-FAIL at (core_test.clj:78)
-These calls were not made the right number of times:
- (first-fake 3) [expected at least once, actually never called]
-^^^^ The previous failure was expected ^^^^
-
-Ran 11 tests containing 17 assertions.
-5 failures, 0 errors.
-{:type :summary, :test 11, :pass 12, :fail 5, :error 0}
View
1 examples/semi-sweet-examples/src/semi_sweet_simple/core.clj
@@ -1 +0,0 @@
-(ns semi-sweet-simple.core)
View
164 examples/semi-sweet-examples/test/semi_sweet_simple/core_test.clj
@@ -1,164 +0,0 @@
-
-(ns semi-sweet-simple.core-test
- (:use clojure.test)
- (:use midje.semi-sweet)
-)
-
-(defn note-expected [] (println "^^^^ The previous failure was expected ^^^^"))
-
- ;;;
-
-;; This is an example of the Midje version of a clojure.test test that would
-;; look like this:
-;; (is (= (+ 1 1) 2))
-;;
-;; Midje uses the clojure.test reporting mechanism, so that you can continue to
-;; use tools that assume clojure.test.
-(deftest example-of-a-simple-equality-test
- (expect (+ 1 1) => 2))
-
-;; Failing tests should look familiar:
-;; FAIL at (core_test.clj:19)
-;; expected: 3
-;; actual: 4
-(deftest example-of-a-simple-equality-test-failure
- (expect ( #(+ 1 %) 3) => 3) (note-expected))
-
-;; You can also use functions on the right-hand side. In that case,
-;; the actual result is passed as the function's single argument.
-(deftest example-of-a-function-as-right-hand-side
- (expect ( #(+ 1 %) 3) => odd?) (note-expected))
-;; The failing test will look slighly different:
-;; FAIL at (core_test.clj:28)
-;; Actual result did not pass expected function.
-;; expected function: odd?
-;; actual result: 4
-
-;; There are a number of matching functions available. You can find them all with
-;; (ns-publics 'midje.checkers)
-;; They have doc strings.
-;; Here's one of them:
-(deftest example-of-a-predefined-checker
- (expect '[3 1 2] => (just [1 2 3] :in-any-order)) ;; succeeds
- (expect '[3 3 1 2] => (just [1 2 3] :in-any-order)) (note-expected))
-;; Actual result did not agree with the checking function.
-;; Actual result: [3 3 1 2]
-;; Checking function: (just [1 2 3] :in-any-order)
-;; The checker said this about the reason:
-;; Expected three elements. There were four.
-
-;; In the semi-sweet version of Midje, functions can be faked out as follows.
-;; As with normal functions, faked functions have to be declared before use.
-(declare first-fake another-fake)
-
-;; Let's suppose we want to test this function but we haven't gotten around to
-;; writing first-fake yet.
-(defn function-under-test-1 [& rest]
- (apply first-fake rest))
-
-;; The following test fakes the first-fake so that it returns a
-;; predefined value when it's called. After that, the result of
-;; function-under-test is checked in the normal way.
-(deftest example-of-a-simple-fake
- (expect (function-under-test-1 3) => 5
- (fake (first-fake 3) => 5)))
-
-;; Here's the failure when a fake is never called
-(defn function-under-test-2 [_] 5)
-(deftest example-of-a-simple-fake-failure
- (expect (function-under-test-2 3) => 5
- (fake (first-fake 3) => 5)) (note-expected))
-;; FAIL for (core_test.clj:80)
-;; This expectation was never satisfied:
-;; (first-fake 3) should be called at least once.
-
-;; If you rerun this test, you'll find that the line number in the
-;; actual error will point to the line containing the (fake)
-;; call. I go to some trouble to get line numbers right. For example,
-;; they should be correct even if the expect and fake are generated by
-;; a macro. Let me know of cases where line numbers are wrong.
-
-
-;; You can describe more than one call to the faked function, and you
-;; can fake more than one function.
-(defn function-under-test-3 []
- (+ (first-fake 1) (first-fake 2 2) (another-fake)))
-(deftest example-of-multiple-faked-functions
- (expect (function-under-test-3) => 111
- (fake (first-fake 1) => 1)
- (fake (first-fake 2 2) => 10)
- (fake (another-fake) => 100)))
-
-;; When looking for a matching fake, Midje 1.1 uses the same rules as
-;; when checking a function-under-test's actual result. Because that's
-;; been found to be confusing, it'll change. Here's future-proof
-;; behavior. Given this function:
-
-(defn function-under-test-4 [value-to-pass]
- (first-fake value-to-pass))
-
-
-(deftest example-of-interesting-functional-args
- ;; Function arguments in checkers are matched literally.
- (expect (function-under-test-4 odd?) => 11
- (fake (first-fake odd?) => 11))
- ;; If you want to use an ordinary function as a checker, wrap it in
- ;; as-checker:
- (expect (function-under-test-4 3) => 11
- (fake (first-fake (as-checker odd?)) => 11))
- ;; You can use predefined checkers as arguments.
- (expect (function-under-test-4 'hops) => 11
- (fake (first-fake anything) => 11))
- (expect (function-under-test-4 3.0) => 11
- (fake (first-fake (roughly 3.0 0.1)) => 11)))
-
-;; The return values of a fake don't follow the rules for fake
-;; arguments. I suppose I could be convinced that a "returning" a
-;; function should be interpreted as returning the value that function
-;; produces when given the actual arguments. I've never seen a need
-;; for that. If you do, let me know.
-
-;; You can insist that a function not be called:
-
-(defn not-caller [n] (+ 1 n))
-(defn some-function-never-called [])
-(deftest example-of-not-called
- (expect (not-caller 3) => 4
- (not-called some-function-never-called)))
-
-;; You can fake a function that's part of Clojure. Suppose we
-;; have a function that operates on two sets. We want to override
-;; clojure.set/intersection so that our tests can only talk about properties
-;; of tests, rather than have to laboriously construct actual sets with those
-;; properties. So we pass in descriptive strings and fake out intersection.
-;;
-;; There is more support for this style in midje.sweet.
-
-(use 'clojure.set)
-(defn set-handler [set1 set2]
- (if (empty? (intersection set1 set2))
- set1
- (intersection set1 set2)))
-
-(deftest example-of-faking-function-from-another-namespace
- "For disjoint sets, return the first."
- (expect (set-handler "some set" "some disjoint set") => "some set"
- (fake (intersection "some set" "some disjoint set") => #{}))
- "For overlapping sets, return the intersection"
- (expect (set-handler "set" "overlapping set") => #{"intersection"}
- (fake (intersection "set" "overlapping set") => #{"intersection"})))
-
-(defn test-ns-hook []
- "This calls the functions in order."
- (example-of-a-simple-equality-test)
- (example-of-a-simple-equality-test-failure)
- (example-of-a-function-as-right-hand-side)
- (example-of-a-predefined-checker)
- (example-of-a-simple-fake)
- (example-of-a-simple-fake-failure)
- (example-of-multiple-faked-functions)
- (example-of-interesting-functional-args)
- (example-of-not-called)
- (example-of-faking-function-from-another-namespace)
-)
-

0 comments on commit e7de9fc

Please sign in to comment.
Something went wrong with that request. Please try again.