Switch from Midje to Speclj[s]
This commit is contained in:
parent
44798d5b4b
commit
ad02da6c88
15 changed files with 49305 additions and 80 deletions
20
bin/specljs_runner.js
Normal file
20
bin/specljs_runner.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#! /usr/bin/env phantomjs
|
||||||
|
|
||||||
|
var fs = require("fs");
|
||||||
|
var p = require('webpage').create();
|
||||||
|
var sys = require('system');
|
||||||
|
|
||||||
|
p.onConsoleMessage = function (x) {
|
||||||
|
fs.write("/dev/stdout", x, "w");
|
||||||
|
};
|
||||||
|
|
||||||
|
p.injectJs(phantom.args[0]);
|
||||||
|
|
||||||
|
var result = p.evaluate(function () {
|
||||||
|
specljs.run.standard.armed = true;
|
||||||
|
return specljs.run.standard.run_specs(
|
||||||
|
cljs.core.keyword("color"), true
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
phantom.exit(result);
|
33
project.clj
33
project.clj
|
@ -3,8 +3,6 @@
|
||||||
:url "http://example.com/FIXME"
|
:url "http://example.com/FIXME"
|
||||||
:license {:name "Eclipse Public License"
|
:license {:name "Eclipse Public License"
|
||||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||||
:source-paths ["src/clj"]
|
|
||||||
:test-paths ["test/clj"]
|
|
||||||
:dependencies [[org.clojure/clojure "1.5.1"]
|
:dependencies [[org.clojure/clojure "1.5.1"]
|
||||||
[http-kit "2.1.8"]
|
[http-kit "2.1.8"]
|
||||||
[compojure "1.1.5"]
|
[compojure "1.1.5"]
|
||||||
|
@ -14,18 +12,25 @@
|
||||||
[prismatic/dommy "0.1.1"]
|
[prismatic/dommy "0.1.1"]
|
||||||
[core.async "0.1.0-SNAPSHOT"]
|
[core.async "0.1.0-SNAPSHOT"]
|
||||||
[com.novemberain/monger "1.5.0"]]
|
[com.novemberain/monger "1.5.0"]]
|
||||||
:profiles {:dev {:dependencies [[midje "1.5.1"]]}}
|
:profiles {:dev {:dependencies [[speclj "2.5.0"]
|
||||||
|
[specljs "2.7.4"]]}}
|
||||||
:plugins [[lein-cljsbuild "0.3.2"]
|
:plugins [[lein-cljsbuild "0.3.2"]
|
||||||
[lein-ring "0.8.6"]]
|
[lein-ring "0.8.6"]
|
||||||
:cljsbuild {
|
[speclj "2.5.0"]
|
||||||
:builds [{
|
[specljs "2.7.4"]]
|
||||||
; The path to the top-level ClojureScript source directory:
|
:cljsbuild ~(let [run-specs ["phantomjs"
|
||||||
:source-paths ["src/cljs"]
|
"bin/specljs_runner.js"
|
||||||
; The standard ClojureScript compiler options:
|
"public/js/grub_dev.js"]]
|
||||||
; (See the ClojureScript compiler documentation for details.)
|
{:builds {:dev {:source-paths ["src/cljs" "spec/cljs"]
|
||||||
:compiler {
|
:compiler {:output-to "public/js/grub_dev.js"
|
||||||
:output-to "public/js/main.js" ; default: target/cljsbuild-main.js
|
:optimizations :whitespace
|
||||||
:optimizations :whitespace
|
:pretty-print true}
|
||||||
:pretty-print true}}]}
|
:notify-command run-specs}
|
||||||
|
:prod {:source-paths ["src/cljs"]
|
||||||
|
:compiler {:output-to "public/js/grub.js"
|
||||||
|
:optimizations :simple}}
|
||||||
|
:test-commands {"test" run-specs}}})
|
||||||
|
:source-paths ["src/clj"]
|
||||||
|
:test-paths ["spec/clj"]
|
||||||
:ring {:handler grub.core/app}
|
:ring {:handler grub.core/app}
|
||||||
:main grub.core)
|
:main grub.core)
|
||||||
|
|
16522
public/js/grub.js
Normal file
16522
public/js/grub.js
Normal file
File diff suppressed because it is too large
Load diff
32661
public/js/grub_dev.js
Normal file
32661
public/js/grub_dev.js
Normal file
File diff suppressed because it is too large
Load diff
54
spec/clj/grub/db_spec.clj
Normal file
54
spec/clj/grub/db_spec.clj
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
(ns grub.db-spec
|
||||||
|
(:require [speclj.core :refer :all]
|
||||||
|
[grub.db :as db]
|
||||||
|
[monger.collection :as mc]
|
||||||
|
[clojure.core.async :refer [>!! <!! timeout]]))
|
||||||
|
|
||||||
|
(def test-db "grub-test")
|
||||||
|
|
||||||
|
(defn short-delay []
|
||||||
|
(<!! (timeout 1)))
|
||||||
|
|
||||||
|
(describe
|
||||||
|
"grub.db"
|
||||||
|
(before (do (db/connect-and-handle-events test-db)
|
||||||
|
(mc/drop db/grub-collection)))
|
||||||
|
(describe "Create grub"
|
||||||
|
(it "should create a grub when a create event comes"
|
||||||
|
(let [test-grub "testgrub"
|
||||||
|
test-id 12345]
|
||||||
|
(>!! @db/incoming-events {:event :create :_id test-id :grub test-grub})
|
||||||
|
(short-delay)
|
||||||
|
(should=
|
||||||
|
{:_id test-id :grub test-grub :completed false}
|
||||||
|
(mc/find-one-as-map db/grub-collection {:_id test-id})))))
|
||||||
|
|
||||||
|
(describe "Complete grub"
|
||||||
|
(it "should complete a grub when a complete event comes"
|
||||||
|
(let [test-grub {:_id 123456 :completed false}]
|
||||||
|
(mc/insert db/grub-collection test-grub)
|
||||||
|
(>!! @db/incoming-events {:event :complete :_id (:_id test-grub)})
|
||||||
|
(short-delay)
|
||||||
|
(should=
|
||||||
|
{:_id (:_id test-grub) :completed true}
|
||||||
|
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)})))))
|
||||||
|
|
||||||
|
(describe "Uncomplete grub"
|
||||||
|
(it "should uncomplete a grub when an uncomplete event comes"
|
||||||
|
(let [test-grub {:_id 123456 :completed true}]
|
||||||
|
(mc/insert db/grub-collection test-grub)
|
||||||
|
(>!! @db/incoming-events {:event :uncomplete :_id (:_id test-grub)})
|
||||||
|
(short-delay)
|
||||||
|
(should=
|
||||||
|
{:_id (:_id test-grub) :completed false}
|
||||||
|
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)})))))
|
||||||
|
|
||||||
|
(describe "Delete grub"
|
||||||
|
(it "should delete a grub when a delete event comes"
|
||||||
|
(let [test-grub {:_id 123456 :completed true}]
|
||||||
|
(mc/insert db/grub-collection test-grub)
|
||||||
|
(>!! @db/incoming-events {:event :delete :_id (:_id test-grub)})
|
||||||
|
(short-delay)
|
||||||
|
(should=
|
||||||
|
nil
|
||||||
|
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}))))))
|
9
spec/cljs/core_spec.cljs
Normal file
9
spec/cljs/core_spec.cljs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
(ns grub.core-spec
|
||||||
|
(:require-macros [specljs.core :refer [describe it should=]])
|
||||||
|
(:require [specljs.core]
|
||||||
|
[grub.core]))
|
||||||
|
|
||||||
|
(describe "A ClojureScript test"
|
||||||
|
(it "fails. Fix it!"
|
||||||
|
(should= 0 1)))
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
[:body
|
[:body
|
||||||
(include-js "http://code.jquery.com/jquery.js")
|
(include-js "http://code.jquery.com/jquery.js")
|
||||||
(include-js "/js/bootstrap.js")
|
(include-js "/js/bootstrap.js")
|
||||||
(include-js "/js/main.js")]))
|
(include-js "/js/grub_dev.js")]))
|
||||||
|
|
||||||
(defroutes routes
|
(defroutes routes
|
||||||
(GET "/ws" [] ws/websocket-handler)
|
(GET "/ws" [] ws/websocket-handler)
|
||||||
|
@ -28,7 +28,6 @@
|
||||||
(route/files "/")
|
(route/files "/")
|
||||||
(route/not-found "<p>Page not found.</p>"))
|
(route/not-found "<p>Page not found.</p>"))
|
||||||
|
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(let [dev? true]
|
(let [dev? true]
|
||||||
(if dev?
|
(if dev?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns grub-client.async-utils
|
(ns grub.async-utils
|
||||||
(:require [cljs.core.async :as async :refer [<! >! chan put! alts!]])
|
(:require [cljs.core.async :as async :refer [<! >! chan put! alts!]])
|
||||||
(:require-macros [cljs.core.async.macros :as m :refer [go]]
|
(:require-macros [cljs.core.async.macros :as m :refer [go]]
|
||||||
[grub-client.macros :refer [go-loop]]))
|
[grub.macros :refer [go-loop]]))
|
||||||
|
|
||||||
(defn put-all! [cs x]
|
(defn put-all! [cs x]
|
||||||
(doseq [c cs]
|
(doseq [c cs]
|
|
@ -1,12 +1,12 @@
|
||||||
(ns grub-client.core
|
(ns grub.core
|
||||||
(:require [grub-client.async-utils
|
(:require [grub.async-utils
|
||||||
:refer [fan-in fan-out event-chan filter-chan do-chan do-chan! map-chan]]
|
:refer [fan-in fan-out event-chan filter-chan do-chan do-chan! map-chan]]
|
||||||
[grub-client.view :as view]
|
[grub.view :as view]
|
||||||
[grub-client.websocket :as ws]
|
[grub.websocket :as ws]
|
||||||
[grub-client.state :as state]
|
[grub.state :as state]
|
||||||
[cljs.core.async :refer [<! >! >!! chan close! timeout]]
|
[cljs.core.async :refer [<! >! >!! chan close! timeout]]
|
||||||
[cljs.reader])
|
[cljs.reader])
|
||||||
(:require-macros [grub-client.macros :refer [log logs go-loop]]
|
(:require-macros [grub.macros :refer [log logs go-loop]]
|
||||||
[cljs.core.async.macros :refer [go]]))
|
[cljs.core.async.macros :refer [go]]))
|
||||||
|
|
||||||
(defn handle-grub-events []
|
(defn handle-grub-events []
|
|
@ -1,4 +1,4 @@
|
||||||
(ns grub-client.macros)
|
(ns grub.macros)
|
||||||
|
|
||||||
(defmacro log [& args]
|
(defmacro log [& args]
|
||||||
`(.log js/console ~@args))
|
`(.log js/console ~@args))
|
|
@ -1,5 +1,5 @@
|
||||||
(ns grub-client.state
|
(ns grub.state
|
||||||
(:require-macros [grub-client.macros :refer [log logs]]))
|
(:require-macros [grub.macros :refer [log logs]]))
|
||||||
|
|
||||||
(def grubs (atom []))
|
(def grubs (atom []))
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
(filter #(= (:_id (second %)) id))
|
(filter #(= (:_id (second %)) id))
|
||||||
(first)
|
(first)
|
||||||
(first))
|
(first))
|
||||||
grub (nth grubs grub-index)]
|
grub (grubs grub-index)]
|
||||||
[grub-index grub]))
|
[grub-index grub]))
|
||||||
|
|
||||||
(defmulti handle-event :event :default :unknown-event)
|
(defmulti handle-event :event :default :unknown-event)
|
|
@ -1,10 +1,10 @@
|
||||||
(ns grub-client.view
|
(ns grub.view
|
||||||
(:require [grub-client.async-utils
|
(:require [grub.async-utils
|
||||||
:refer [do-chan! do-chan event-chan map-chan fan-in filter-chan]]
|
:refer [do-chan! do-chan event-chan map-chan fan-in filter-chan]]
|
||||||
[grub-client.state :as state]
|
[grub.state :as state]
|
||||||
[dommy.core :as dommy]
|
[dommy.core :as dommy]
|
||||||
[cljs.core.async :refer [<! >! chan]])
|
[cljs.core.async :refer [<! >! chan]])
|
||||||
(:require-macros [grub-client.macros :refer [log logs go-loop]]
|
(:require-macros [grub.macros :refer [log logs go-loop]]
|
||||||
[dommy.macros :refer [deftemplate sel1 node]]
|
[dommy.macros :refer [deftemplate sel1 node]]
|
||||||
[cljs.core.async.macros :refer [go]]))
|
[cljs.core.async.macros :refer [go]]))
|
||||||
|
|
||||||
|
@ -102,11 +102,9 @@
|
||||||
sorted-grubs (sort-by :_id grubs)]
|
sorted-grubs (sort-by :_id grubs)]
|
||||||
(aset grub-list "innerHTML" "")
|
(aset grub-list "innerHTML" "")
|
||||||
(doseq [grub sorted-grubs]
|
(doseq [grub sorted-grubs]
|
||||||
(logs "render-grub-list:" grub)
|
|
||||||
(dommy/append! grub-list (grub-template grub)))))
|
(dommy/append! grub-list (grub-template grub)))))
|
||||||
|
|
||||||
(add-watch state/grubs
|
(add-watch state/grubs
|
||||||
:grub-add-watch
|
:grub-add-watch
|
||||||
(fn [key ref old new]
|
(fn [key ref old new]
|
||||||
(logs "state:" new)
|
|
||||||
(render-grub-list new)))
|
(render-grub-list new)))
|
|
@ -1,9 +1,9 @@
|
||||||
(ns grub-client.websocket
|
(ns grub.websocket
|
||||||
(:require [grub-client.async-utils
|
(:require [grub.async-utils
|
||||||
:refer [fan-in fan-out event-chan filter-chan do-chan do-chan! map-chan]]
|
:refer [fan-in fan-out event-chan filter-chan do-chan do-chan! map-chan]]
|
||||||
[cljs.core.async :refer [<! >! >!! chan close! timeout]]
|
[cljs.core.async :refer [<! >! >!! chan close! timeout]]
|
||||||
[cljs.reader])
|
[cljs.reader])
|
||||||
(:require-macros [grub-client.macros :refer [log logs go-loop]]
|
(:require-macros [grub.macros :refer [log logs go-loop]]
|
||||||
[cljs.core.async.macros :refer [go]]))
|
[cljs.core.async.macros :refer [go]]))
|
||||||
|
|
||||||
(def websocket* (atom nil))
|
(def websocket* (atom nil))
|
||||||
|
@ -14,7 +14,6 @@
|
||||||
(defn get-remote-events []
|
(defn get-remote-events []
|
||||||
(let [out (chan)]
|
(let [out (chan)]
|
||||||
(aset @websocket* "onmessage" (fn [event]
|
(aset @websocket* "onmessage" (fn [event]
|
||||||
(logs "received event" event)
|
|
||||||
(let [grub-event (cljs.reader/read-string (.-data event))]
|
(let [grub-event (cljs.reader/read-string (.-data event))]
|
||||||
(logs "Received:" grub-event)
|
(logs "Received:" grub-event)
|
||||||
(go (>! out grub-event)))))
|
(go (>! out grub-event)))))
|
|
@ -1,3 +0,0 @@
|
||||||
(ns grub.core-test
|
|
||||||
(:use clojure.test
|
|
||||||
grub.core))
|
|
|
@ -1,39 +0,0 @@
|
||||||
(ns grub.db-test
|
|
||||||
(:require [midje.sweet :refer [fact with-state-changes contains anything]]
|
|
||||||
[monger.collection :as mc]
|
|
||||||
[grub.db :as db]
|
|
||||||
[clojure.core.async :refer [>!!]]))
|
|
||||||
|
|
||||||
(def test-db "grub-test")
|
|
||||||
|
|
||||||
(with-state-changes [(before :facts (do (db/connect-and-handle-events test-db)
|
|
||||||
(mc/drop db/grub-collection)))]
|
|
||||||
(fact
|
|
||||||
"Create grub"
|
|
||||||
(fact "sending an event creates a grub"
|
|
||||||
(let [test-grub "testgrub"
|
|
||||||
test-id 12345]
|
|
||||||
(>!! @db/incoming-events {:event :create :_id test-id :grub test-grub})
|
|
||||||
(mc/find-one-as-map db/grub-collection {:_id test-id}) =>
|
|
||||||
{:_id test-id :grub test-grub :completed false})))
|
|
||||||
(fact "Complete grub"
|
|
||||||
(fact "sending an event completes a grub"
|
|
||||||
(let [test-grub {:_id 123456 :completed false}]
|
|
||||||
(mc/insert db/grub-collection test-grub)
|
|
||||||
(>!! @db/incoming-events {:event :complete :_id (:_id test-grub)})
|
|
||||||
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}) =>
|
|
||||||
{:_id (:_id test-grub) :completed true})))
|
|
||||||
(fact "Uncomplete grub"
|
|
||||||
(fact "sending an event uncompletes a grub"
|
|
||||||
(let [test-grub {:_id 123456 :completed true}]
|
|
||||||
(mc/insert db/grub-collection test-grub)
|
|
||||||
(>!! @db/incoming-events {:event :uncomplete :_id (:_id test-grub)})
|
|
||||||
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}) =>
|
|
||||||
{:_id (:_id test-grub) :completed false})))
|
|
||||||
(fact "Delete grub"
|
|
||||||
(fact "sending an event deletes a grub"
|
|
||||||
(let [test-grub {:_id 123456 :completed true}]
|
|
||||||
(mc/insert db/grub-collection test-grub)
|
|
||||||
(>!! @db/incoming-events {:event :delete :_id (:_id test-grub)})
|
|
||||||
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}) =>
|
|
||||||
nil))))
|
|
Loading…
Reference in a new issue