Permalink
Browse files

adds should-not== for non-collections. documents equivalency assertions

  • Loading branch information...
1 parent f94bad7 commit addbe5aa52bed80b1d8fd2cc49fdbc68789e9c0a @slagyr committed Dec 21, 2012
Showing with 124 additions and 120 deletions.
  1. +5 −0 CHANGES.md
  2. +5 −5 README.md
  3. +65 −46 spec/speclj/should_spec.clj
  4. +7 −31 speclj.iml
  5. +41 −37 src/speclj/core.clj
  6. +1 −1 src/speclj/version.clj
View
@@ -1,3 +1,8 @@
+# 2.5.0
+
+* should== for loose equality and collection containment equality
+* should-not== opposite of should==
+
# 2.4.0
* should-contain works with regular expressions, maps, and sequences
View
@@ -72,7 +72,7 @@ Checkout this example spec file. It would be located at `sample_project/spec/sam
(run-specs)
```
-### speclj.core namespace
+### `speclj.core` namespace
Your spec files should `:use` the `speclj.core` in it's entirety. It's a clean namespace and you're likely going to use all the definitions within it. Don't forget to pull in the library that you're testing as well (sample.core in this case).
```clojure
@@ -81,21 +81,21 @@ Your spec files should `:use` the `speclj.core` in it's entirety. It's a clean
[sample.core])
```
-### describe
+### `describe`
`describe` is the outer most container for specs. It takes a `String` name and any number of _spec components_.
```clojure
(describe "Truth" ...)
```
-### it
+### `it`
`it` specifies a _characteristic_ of the subject. This is where assertions go. Be sure to provide good names as the first parameter of `it` calls.
```clojure
(it "is true" ...)
```
-### should and should-not
+### `should` and `should-not`
Assertions. All assertions begin with `should`. `should` and `should-not` are just two of the many assertions available. They both take expressions that they will check for truthy-ness and falsy-ness respectively.
```clojure
@@ -110,7 +110,7 @@ At the very end of the file is an invocation of `(run-specs)`. This will invoke
(run-specs)
```
-## should Variants
+## `should` Variants (Assertions)
There are several ways to make assertions. They are documented on the wiki: [Should Variants](https://github.com/slagyr/speclj/wiki/Should-variants)
## Spec Components
@@ -1,8 +1,7 @@
(ns speclj.should-spec
- (:use
- [speclj.core]
- [speclj.spec-helper]
- [speclj.util :only (endl)]))
+ (:use [speclj.core]
+ [speclj.spec-helper]
+ [speclj.util :only (endl)]))
(describe "Should Assertions: "
(it "should tests truthy"
@@ -114,85 +113,105 @@
(should-fail! (should== [1 2 3] [1 2 3 4])))
(it "reports extra items"
- (let [message (str "Expected collection contained: <[1 2 3]>" endl "Actual collection contained: <[1 2 3 4]>" endl "The extra elements were: <[4]> (using =)")]
+ (let [message (str "Expected contents: <[1 2 3]>" endl " got: <[1 2 3 4]>" endl " missing: <[]>" endl " extra: <[4]>")]
(should= message (failure-message (should== [1 2 3] [1 2 3 4])))))
(it "fails if target is missing items"
(should-fail! (should== [1 2 3] [1 2])))
(it "reports missing items"
- (let [message (str "Expected collection contained: <[1 2 3]>" endl "Actual collection contained: <[1 2]>" endl "The missing elements were: <[3]> (using =)")]
+ (let [message (str "Expected contents: <[1 2 3]>" endl " got: <[1 2]>" endl " missing: <[3]>" endl " extra: <[]>")]
(should= message (failure-message (should== [1 2 3] [1 2])))))
(it "fails if target is missing items and has extra items"
(should-fail! (should== [1 2 3] [1 2 4])))
(it "reports missing and extra items"
- (let [message (str "Expected collection contained: <[1 2 3]>" endl "Actual collection contained: <[1 2 4]>" endl "The missing elements were: <[3]>" endl "The extra elements were: <[4]> (using =)")]
+ (let [message (str "Expected contents: <[1 2 3]>" endl " got: <[1 2 4]>" endl " missing: <[3]>" endl " extra: <[4]>")]
(should= message (failure-message (should== [1 2 3] [1 2 4])))))
(it "fails if there are duplicates in the target"
(should-fail! (should== [1 5] [1 1 1 5])))
(it "reports extra duplicates"
- (let [message (str "Expected collection contained: <[1 5]>" endl "Actual collection contained: <[1 1 1 5]>" endl "The extra elements were: <[1 1]> (using =)")]
- (should= message (failure-message (should== [1 5] [1 1 1 5])))))
+ (let [message (str "Expected contents: <[1 5]>" endl " got: <[1 1 1 5]>" endl " missing: <[]>" endl " extra: <[1 1]>")]
+ (should= message (failure-message (should== [1 5] [1 1 1 5])))))
(it "fails if there are duplicates in the expected"
(should-fail! (should== [1 1 1 5] [1 5])))
(it "reports missing duplicates"
- (let [message (str "Expected collection contained: <[1 1 1 5]>" endl "Actual collection contained: <[1 5]>" endl "The missing elements were: <[1 1]> (using =)")]
- (should= message (failure-message (should== [1 1 1 5] [1 5])))))
+ (let [message (str "Expected contents: <[1 1 1 5]>" endl " got: <[1 5]>" endl " missing: <[1 1]>" endl " extra: <[]>")]
+ (should= message (failure-message (should== [1 1 1 5] [1 5])))))
(it "prints lazyseqs"
- (let [message (str "Expected collection contained: <(1 1 1 5)>" endl "Actual collection contained: <[1 5]>" endl "The missing elements were: <[1 1]> (using =)")]
- (should= message (failure-message (should== (lazy-seq [1 1 1 5]) [1 5])))))
+ (let [message (str "Expected contents: <(1 1 1 5)>" endl " got: <[1 5]>" endl " missing: <[1 1]>" endl " extra: <[]>")]
+ (should= message (failure-message (should== (lazy-seq [1 1 1 5]) [1 5])))))
(it "prints lists"
- (let [message (str "Expected collection contained: <(1 1 1 5)>" endl "Actual collection contained: <[1 5]>" endl "The missing elements were: <[1 1]> (using =)")]
- (should= message (failure-message (should== (list 1 1 1 5) [1 5])))))
+ (let [message (str "Expected contents: <(1 1 1 5)>" endl " got: <[1 5]>" endl " missing: <[1 1]>" endl " extra: <[]>")]
+ (should= message (failure-message (should== (list 1 1 1 5) [1 5])))))
(it "prints sets"
- (let [message (str "Expected collection contained: <[1 1 1 5]>" endl "Actual collection contained: <#{1 5}>" endl "The missing elements were: <[1 1]> (using =)")]
- (should= message (failure-message (should== [1 1 1 5] #{1 5})))))
+ (let [message (str "Expected contents: <[1 1 1 5]>" endl " got: <#{1 5}>" endl " missing: <[1 1]>" endl " extra: <[]>")]
+ (should= message (failure-message (should== [1 1 1 5] #{1 5})))))
- ))
+ ))
(context "should-not=="
- (it "fails if target contains all items"
- (should-fail! (should-not== [1 2 3] [1 2 3])))
- (it "fails if target contains all items out of order"
- (should-fail! (should-not== [1 2 3] [1 3 2])))
+ (context "numbers"
+ (it "tests loose equality"
+ (should-fail! (should-not== 1 1))
+ (should-fail! (should-not== 1 1.0))
+ (should-fail! (should-not== (int 1) (long 1)))
+ (should-pass! (should-not== 1 2))
+ (should-pass! (should-not== 1 2.0)))
+
+ (it "reports the error"
+ (let [error (str " Expected: <1>" endl "not to ==: <1> (using ==)")]
+ (should= error (failure-message (should-not== 1 1)))))
+
+ (it "reports the error with floats"
+ (let [error (str " Expected: <1.0>" endl "not to ==: <1> (using ==)")]
+ (should= error (failure-message (should-not== 1.0 1)))))
+
+ )
- (it "passes if target includes extra items"
- (should-pass! (should-not== [1 2 3] [1 2 3 4])))
+ (context "two collections"
+ (it "fails if target contains all items"
+ (should-fail! (should-not== [1 2 3] [1 2 3])))
- (it "passes if target is missing items"
- (should-pass! (should-not== [1 2 3] [1 2])))
+ (it "fails if target contains all items out of order"
+ (should-fail! (should-not== [1 2 3] [1 3 2])))
- (it "passes if target is missing items and has extra items"
- (should-pass! (should-not== [1 2 3] [1 2 4])))
+ (it "passes if target includes extra items"
+ (should-pass! (should-not== [1 2 3] [1 2 3 4])))
- (it "passes if there are duplicates in the target"
- (should-pass! (should-not== [1 5] [1 1 1 5])))
+ (it "passes if target is missing items"
+ (should-pass! (should-not== [1 2 3] [1 2])))
- (it "passes if there are duplicates in the expected"
- (should-pass! (should-not== [1 1 1 5] [1 5])))
+ (it "passes if target is missing items and has extra items"
+ (should-pass! (should-not== [1 2 3] [1 2 4])))
- (it "prints lazyseqs"
- (let [message (str "Expected: <(1 5)>" endl "not to contain: <[1 5]> (using =)")]
- (should= message (failure-message (should-not== (lazy-seq [1 5]) [1 5])))))
+ (it "passes if there are duplicates in the target"
+ (should-pass! (should-not== [1 5] [1 1 1 5])))
- (it "prints lists"
- (let [message (str "Expected: <(1 5)>" endl "not to contain: <[1 5]> (using =)")]
- (should= message (failure-message (should-not== (list 1 5) [1 5])))))
+ (it "passes if there are duplicates in the expected"
+ (should-pass! (should-not== [1 1 1 5] [1 5])))
- (it "prints sets"
- (let [message (str "Expected: <#{1 5}>" endl "not to contain: <[1 5]> (using =)")]
- (should= message (failure-message (should-not== (set [1 5]) [1 5])))))
+ (it "prints lazyseqs"
+ (let [message (str "Expected contents: <(1 5)>" endl " to differ from: <[1 5]>")]
+ (should= message (failure-message (should-not== (lazy-seq [1 5]) [1 5])))))
+ (it "prints lists"
+ (let [message (str "Expected contents: <(1 5)>" endl " to differ from: <[1 5]>")]
+ (should= message (failure-message (should-not== (list 1 5) [1 5])))))
+
+ (it "prints sets"
+ (let [message (str "Expected contents: <#{1 5}>" endl " to differ from: <[1 5]>")]
+ (should= message (failure-message (should-not== (set [1 5]) [1 5])))))
+ )
)
(it "should-contain checks for containmentship of precise strings"
@@ -272,7 +291,7 @@
(should-pass! (should-throw (throw (Throwable. "error"))))
(should-fail! (should-throw (+ 1 1)))
(should= (str "Expected java.lang.Throwable thrown from: (+ 1 1)" endl
- " but got: <nothing thrown>")
+ " but got: <nothing thrown>")
(failure-message (should-throw (+ 1 1)))))
(it "should-throw can test an expected throwable type"
@@ -281,10 +300,10 @@
(should-fail! (should-throw NullPointerException (throw (Exception.))))
(should-fail! (should-throw NullPointerException (+ 1 1)))
(should= (str "Expected java.lang.NullPointerException thrown from: (+ 1 1)" endl
- " but got: <nothing thrown>")
+ " but got: <nothing thrown>")
(failure-message (should-throw NullPointerException (+ 1 1))))
(should= (str "Expected java.lang.NullPointerException thrown from: (throw (Exception. \"some message\"))" endl
- " but got: java.lang.Exception: some message")
+ " but got: java.lang.Exception: some message")
(failure-message (should-throw NullPointerException (throw (Exception. "some message"))))))
(it "should-throw can test the message of the exception"
@@ -299,9 +318,9 @@
(should-pass! (should-not-throw (+ 1 1)))
(should-fail! (should-not-throw (throw (Throwable. "error"))))
(should= (str "Expected nothing thrown from: (throw (Throwable. \"error\"))" endl
- " but got: java.lang.Throwable: error")
+ " but got: java.lang.Throwable: error")
(failure-message (should-not-throw (throw (Throwable. "error"))))))
)
-(run-specs)
+(run-specs :stacktrace true)
View
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Clojure" name="Clojure">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/classes" />
- <output-test url="file://$MODULE_DIR$/classes" />
- <exclude-output />
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -27,39 +27,15 @@
<orderEntry type="module-library">
<library>
<CLASSES>
- <root url="jar://$MODULE_DIR$/lib/mmargs-1.2.0.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
<root url="file://$MODULE_DIR$/src" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/lib/fresh-1.0.2.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/lib/clojure-1.4.0-alpha3.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
+ <orderEntry type="library" name="Maven: org.clojure:clojure:1.4.0" level="project" />
+ <orderEntry type="library" name="Maven: fresh:fresh:1.0.2" level="project" />
+ <orderEntry type="library" name="Maven: mmargs:mmargs:1.2.0" level="project" />
</component>
</module>
Oops, something went wrong.

0 comments on commit addbe5a

Please sign in to comment.