-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for core.loader.clj and small change v0.2 (#159)
* save for now * codeclimate says dorun is non-idio -- so switching to doseq since we just want the side effects * be explicit about what "YB-all-namespaces" means * small optimization when finding and loading namespaces * found an issue where namespaces were being "double loaded" -- using distinct to make unique * put it all back to normal but include distinct fix * small movements * use original src loader.clj, drop test related to checking for dups * load all commands in cmd fact * try it all again
- Loading branch information
1 parent
ec12947
commit 465de69
Showing
3 changed files
with
40 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
(ns yetibot.core.test.commands.cmd | ||
(:require | ||
[midje.sweet :refer [fact => contains has-prefix just]] | ||
[matcher-combinators.midje :refer [match]] | ||
[yetibot.core.midje :refer [value data error]] | ||
[yetibot.core.commands.cmd :refer [cmd]])) | ||
[midje.sweet :refer [fact =>]] | ||
[yetibot.core.commands.cmd :refer [cmd]] | ||
[yetibot.core.loader :as loader])) | ||
|
||
(fact | ||
"cmd should work as expected" | ||
(cmd {:match "echo hi"}) => "hi") | ||
(fact "cmd should work as expected" | ||
(loader/load-commands) | ||
(cmd {:match "echo hi"}) => "hi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
(ns yetibot.core.test.loader | ||
(:require | ||
[yetibot.core.loader :as loader] | ||
[clojure.test :refer :all])) | ||
|
||
(deftest loader | ||
(testing | ||
"Loading all namespaces. This can help find invalid requires or errors in | ||
code at test time (instead of waiting till runtime)" | ||
(loader/load-observers) | ||
(loader/load-commands))) | ||
(:require [yetibot.core.loader :as loader] | ||
[midje.sweet :refer [=> =not=> contains fact facts every-checker]])) | ||
|
||
(fact "all-namespaces returns non-empty collection that contains expected namespace" | ||
(loader/all-namespaces) | ||
=> (every-checker coll? not-empty (contains 'yetibot.core.loader))) | ||
|
||
(facts "about load-ns" | ||
(fact "loads a legit namesapce and returns said namespace" | ||
(loader/load-ns 'yetibot.core.commands.help) | ||
=> 'yetibot.core.commands.help) | ||
(fact "returns nil when loading illegitimate namespace" | ||
(loader/load-ns 'i.am.fake) => nil)) | ||
|
||
(facts "about find-and-load-namespaces" | ||
(let [patterns '(#"yetibot\.core\.commands\.help" | ||
#"yetibot\.core\.commands\.error") | ||
nss (loader/find-and-load-namespaces patterns) | ||
nss-count (count nss)] | ||
(fact "results is non-empty collection that contains expected namespace" | ||
nss => (every-checker coll? not-empty) (contains 'yetibot.core.commands.help)) | ||
(fact "results is exactly 2 commands" | ||
nss-count => 2) | ||
(fact "results don't contain extraneous namespaces" | ||
nss =not=> (contains 'yetibot.core.commands.echo)))) | ||
|
||
(fact "load-observers returns a non-empty collection" | ||
(loader/load-observers) => (every-checker coll? not-empty)) | ||
|
||
(fact "load-commands returns a non-empty collection" | ||
(loader/load-commands) => (every-checker coll? not-empty)) |