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);
|
31
project.clj
31
project.clj
|
@ -3,8 +3,6 @@
|
|||
:url "http://example.com/FIXME"
|
||||
:license {:name "Eclipse Public License"
|
||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||
:source-paths ["src/clj"]
|
||||
:test-paths ["test/clj"]
|
||||
:dependencies [[org.clojure/clojure "1.5.1"]
|
||||
[http-kit "2.1.8"]
|
||||
[compojure "1.1.5"]
|
||||
|
@ -14,18 +12,25 @@
|
|||
[prismatic/dommy "0.1.1"]
|
||||
[core.async "0.1.0-SNAPSHOT"]
|
||||
[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"]
|
||||
[lein-ring "0.8.6"]]
|
||||
:cljsbuild {
|
||||
:builds [{
|
||||
; The path to the top-level ClojureScript source directory:
|
||||
:source-paths ["src/cljs"]
|
||||
; The standard ClojureScript compiler options:
|
||||
; (See the ClojureScript compiler documentation for details.)
|
||||
:compiler {
|
||||
:output-to "public/js/main.js" ; default: target/cljsbuild-main.js
|
||||
[lein-ring "0.8.6"]
|
||||
[speclj "2.5.0"]
|
||||
[specljs "2.7.4"]]
|
||||
:cljsbuild ~(let [run-specs ["phantomjs"
|
||||
"bin/specljs_runner.js"
|
||||
"public/js/grub_dev.js"]]
|
||||
{:builds {:dev {:source-paths ["src/cljs" "spec/cljs"]
|
||||
:compiler {:output-to "public/js/grub_dev.js"
|
||||
: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}
|
||||
: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
|
||||
(include-js "http://code.jquery.com/jquery.js")
|
||||
(include-js "/js/bootstrap.js")
|
||||
(include-js "/js/main.js")]))
|
||||
(include-js "/js/grub_dev.js")]))
|
||||
|
||||
(defroutes routes
|
||||
(GET "/ws" [] ws/websocket-handler)
|
||||
|
@ -28,7 +28,6 @@
|
|||
(route/files "/")
|
||||
(route/not-found "<p>Page not found.</p>"))
|
||||
|
||||
|
||||
(def app
|
||||
(let [dev? true]
|
||||
(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-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]
|
||||
(doseq [c cs]
|
|
@ -1,12 +1,12 @@
|
|||
(ns grub-client.core
|
||||
(:require [grub-client.async-utils
|
||||
(ns grub.core
|
||||
(:require [grub.async-utils
|
||||
:refer [fan-in fan-out event-chan filter-chan do-chan do-chan! map-chan]]
|
||||
[grub-client.view :as view]
|
||||
[grub-client.websocket :as ws]
|
||||
[grub-client.state :as state]
|
||||
[grub.view :as view]
|
||||
[grub.websocket :as ws]
|
||||
[grub.state :as state]
|
||||
[cljs.core.async :refer [<! >! >!! chan close! timeout]]
|
||||
[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]]))
|
||||
|
||||
(defn handle-grub-events []
|
|
@ -1,4 +1,4 @@
|
|||
(ns grub-client.macros)
|
||||
(ns grub.macros)
|
||||
|
||||
(defmacro log [& args]
|
||||
`(.log js/console ~@args))
|
|
@ -1,5 +1,5 @@
|
|||
(ns grub-client.state
|
||||
(:require-macros [grub-client.macros :refer [log logs]]))
|
||||
(ns grub.state
|
||||
(:require-macros [grub.macros :refer [log logs]]))
|
||||
|
||||
(def grubs (atom []))
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
|||
(filter #(= (:_id (second %)) id))
|
||||
(first)
|
||||
(first))
|
||||
grub (nth grubs grub-index)]
|
||||
grub (grubs grub-index)]
|
||||
[grub-index grub]))
|
||||
|
||||
(defmulti handle-event :event :default :unknown-event)
|
|
@ -1,10 +1,10 @@
|
|||
(ns grub-client.view
|
||||
(:require [grub-client.async-utils
|
||||
(ns grub.view
|
||||
(:require [grub.async-utils
|
||||
: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]
|
||||
[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]]
|
||||
[cljs.core.async.macros :refer [go]]))
|
||||
|
||||
|
@ -102,11 +102,9 @@
|
|||
sorted-grubs (sort-by :_id grubs)]
|
||||
(aset grub-list "innerHTML" "")
|
||||
(doseq [grub sorted-grubs]
|
||||
(logs "render-grub-list:" grub)
|
||||
(dommy/append! grub-list (grub-template grub)))))
|
||||
|
||||
(add-watch state/grubs
|
||||
:grub-add-watch
|
||||
(fn [key ref old new]
|
||||
(logs "state:" new)
|
||||
(render-grub-list new)))
|
|
@ -1,9 +1,9 @@
|
|||
(ns grub-client.websocket
|
||||
(:require [grub-client.async-utils
|
||||
(ns grub.websocket
|
||||
(:require [grub.async-utils
|
||||
:refer [fan-in fan-out event-chan filter-chan do-chan do-chan! map-chan]]
|
||||
[cljs.core.async :refer [<! >! >!! chan close! timeout]]
|
||||
[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]]))
|
||||
|
||||
(def websocket* (atom nil))
|
||||
|
@ -14,7 +14,6 @@
|
|||
(defn get-remote-events []
|
||||
(let [out (chan)]
|
||||
(aset @websocket* "onmessage" (fn [event]
|
||||
(logs "received event" event)
|
||||
(let [grub-event (cljs.reader/read-string (.-data event))]
|
||||
(logs "Received:" 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