Skip to content

Instantly share code, notes, and snippets.

@CampingScorpion
CampingScorpion / gist:1569517
Created January 6, 2012 07:29
rewrite of put-get-json-default
;; original
(deftest put-get-json-default
(let [obj {:value [1 "2" '(3)]}
put-ret (client/put c "test-bucket" "test-key" obj)
get-ret (client/get c "test-bucket" "test-key")]
(is (= (:value obj)
(:value (first get-ret))))))
;; my Midje version
@CampingScorpion
CampingScorpion / gist:1580643
Created January 9, 2012 02:18
work on chatty destructuring of maps
;; TESTS
;; Destructuring arguments
(def actual-plus-one-equals-4 (chatty-checker [actual] (= (inc actual) 4)))
(def vec-structured-checker
(chatty-checker [ [a b & c]]
(and (= a 1)
(= b 2)
@CampingScorpion
CampingScorpion / gist:1614509
Created January 15, 2012 05:36
Midje `formula`
;; This first swipe at generative-style testing in Midje was super easy:
;; first a use of it
(defn make-string []
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))
(formula [a (make-string) b (make-string)]
(str a b) => #(.startsWith % a))
(defmacro def+keep-meta [name a-var]
`(alter-meta! (def ~name ~a-var) merge (meta ~a-var)))
@CampingScorpion
CampingScorpion / gist:1861626
Created February 19, 2012 02:15
Mutable objects!
(defn make-foo [n]
(let [foo (atom n)]
{:update (fn [n] (reset! foo n))
:inc (fn [] (swap! foo inc))
:status (fn [] (print @foo))} ))
(defmacro defobject
"doesn't work yet"
[name field-vec & methods]
(let [methods (partition 3 methods)
@CampingScorpion
CampingScorpion / gist:1870159
Created February 20, 2012 17:14
Formula example syntax
;; Example of midje formula
(defn make-string
"A generator for 'random' string values - could use the ones from test.generative"
[]
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))
(formula
"can now use simple generative-style formulas"
[a (make-string) b (make-string)]
@CampingScorpion
CampingScorpion / gist:1890368
Created February 23, 2012 04:52
bultitude attempt
(ns leiningen.midje
(:refer-clojure :exclude [test])
(:use [bultitude.core :only [namespaces-in-dir namespaces-on-classpath]] ;; changed
[leiningen.test :only [*exit-after-tests*]]
[leiningen.compile :only [eval-in-project]]
[clojure.set :only [difference]]))
;; ...
@CampingScorpion
CampingScorpion / gist:1998029
Created March 8, 2012 02:03
formula with shrinking incorporated ... not perfect at all yet
(ns ^{:doc "Midje's special blend of generative-style testing."}
midje.ideas.formulas
(:use [midje.util.form-utils :only [pop-docstring]]
[midje.error-handling.validation-errors :only [simple-report-validation-error validate when-valid]]
[midje.ideas.arrows :only [leaves-contain-arrow?]]))
(def ^{:doc "The number of facts generated per formula."
:dynamic true}
*num-generations-per-formula* 100)
(def g
[[:a1 :rdf/type :sdx/FederationService]
[:a1 :sdx/exposesServices :a2]
[:a2 :rdf/type :sdx/ServiceCollection]
[:a2 :sdx/service :b1]
[:a2 :sdx/service :c1]
[:a2 :sdx/service :d1]
[:b1 :rdf/type :sdx/FederatedService]
[:b1 :sdx/exposesServices :b2]
@CampingScorpion
CampingScorpion / gist:2233328
Created March 29, 2012 04:36
state monad as a way to hold 'world' state
(defmacro defworld [name bindings & body]
`(defn ~name ~bindings
(fn [~'world]
(println ~'world)
~@body)))
(defmacro with-world [& body]
`(domonad state-m
~@body))