-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement before-each and after-each
- Loading branch information
1 parent
9d04097
commit 89dfb6c
Showing
7 changed files
with
228 additions
and
49 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
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
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,67 +1,187 @@ | ||
(ns lazytest.context-test | ||
(:require | ||
[lazytest.core :refer [after before defdescribe describe expect-it given around it expect]])) | ||
[lazytest.context :refer [propagate-eachs]] | ||
[lazytest.core :refer [after after-each around before before-each | ||
defdescribe describe expect expect-it given it]])) | ||
|
||
(defn vconj! [volatile value] | ||
(vswap! volatile conj value)) | ||
|
||
(defdescribe context-test | ||
(describe "on suites" | ||
(given [state (volatile! [])] | ||
(describe "manual maps" | ||
{:context [{:before (fn [] (vswap! state conj :before)) | ||
:after (fn [] (vswap! state conj :after))}]} | ||
(expect-it "temp" true)) | ||
{:context [{:before (fn [] (vconj! state :before)) | ||
:after (fn [] (vconj! state :after))}]} | ||
(expect-it "temp" (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:before :after] @state))) | ||
(= [:before :expect :after] @state))) | ||
(given [state (volatile! [])] | ||
(describe before | ||
{:context [(before (vswap! state conj :before))]} | ||
(expect-it "temp" true)) | ||
{:context [(before (vconj! state :before))]} | ||
(expect-it "temp" (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:before] @state))) | ||
(= [:before :expect] @state))) | ||
(given [state (volatile! [])] | ||
(describe after | ||
{:context [(after (vswap! state conj :after))]} | ||
(expect-it "temp" true)) | ||
{:context [(after (vconj! state :after))]} | ||
(expect-it "temp" (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:after] @state))) | ||
(= [:expect :after] @state))) | ||
(given [state (volatile! [])] | ||
(describe "not order dependent" | ||
{:context [(after (vswap! state conj :after)) | ||
(before (vswap! state conj :before))]} | ||
(expect-it "temp" true)) | ||
{:context [(after (vconj! state :after)) | ||
(before (vconj! state :before))]} | ||
(expect-it "temp" (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:before :after] @state))) | ||
(= [:before :expect :after] @state))) | ||
(given [state (volatile! [])] | ||
(describe "around" | ||
{:context [{:around (fn [f] | ||
(vswap! state conj :around-before) | ||
(vconj! state :around-before) | ||
(f) | ||
(vswap! state conj :around-after))}]} | ||
(expect-it "temp" true)) | ||
(vconj! state :around-after))}]} | ||
(expect-it "temp" (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:around-before :around-after] @state))) | ||
(= [:around-before :expect :around-after] @state))) | ||
(given [state (volatile! [])] | ||
(describe around | ||
{:context [(around [f] | ||
(vswap! state conj :around-before) | ||
(vconj! state :around-before) | ||
(f) | ||
(vswap! state conj :around-after))]} | ||
(expect-it "temp" true)) | ||
(vconj! state :around-after))]} | ||
(expect-it "temp" (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:around-before :around-after] @state)))) | ||
(= [:around-before :expect :around-after] @state))) | ||
(describe before-each | ||
(given [state (volatile! [])] | ||
(describe "inner" | ||
{:context [(before-each (vconj! state :before-each))]} | ||
(expect-it "temp 1" (vconj! state :expect-1)) | ||
(expect-it "temp 2" (vconj! state :expect-2)) | ||
(expect-it "temp 3" (vconj! state :expect-3))) | ||
(expect-it "tracks correctly" | ||
(= [:before-each :expect-1 :before-each :expect-2 :before-each :expect-3] @state)))) | ||
(describe after-each | ||
(given [state (volatile! [])] | ||
(describe "inner" | ||
{:context [(after-each (vconj! state :after-each))]} | ||
(expect-it "temp 1" (vconj! state :expect-1)) | ||
(expect-it "temp 2" (vconj! state :expect-2)) | ||
(expect-it "temp 3" (vconj! state :expect-3))) | ||
(expect-it "tracks correctly" | ||
(= [:expect-1 :after-each :expect-2 :after-each :expect-3 :after-each] @state)))) | ||
(describe "both before-each and after-each" | ||
(given [state (volatile! [])] | ||
(describe "inner" | ||
{:context [(before-each (vconj! state :before-each)) | ||
(after-each (vconj! state :after-each))]} | ||
(expect-it "temp 1" (vconj! state :expect-1)) | ||
(expect-it "temp 2" (vconj! state :expect-2))) | ||
(expect-it "tracks correctly" | ||
(= [:before-each :expect-1 :after-each :before-each :expect-2 :after-each] @state)))) | ||
(describe "complex flat case" | ||
(given [state (volatile! [])] | ||
(describe "inner" | ||
{:context [(before (vconj! state :before)) | ||
(before-each (vconj! state :before-each)) | ||
(after-each (vconj! state :after-each)) | ||
(after (vconj! state :after))]} | ||
(expect-it "temp 1" (vconj! state :expect-1)) | ||
(expect-it "temp 2" (vconj! state :expect-2))) | ||
(expect-it "tracks correctly" | ||
(= [:before :before-each :expect-1 :after-each :before-each :expect-2 :after-each :after] @state))))) | ||
(describe "on test cases" | ||
(given [state (volatile! [])] | ||
(it "works correctly" | ||
{:context [(before (vswap! state conj :before)) | ||
(after (vswap! state conj :after))]} | ||
(expect true)) | ||
{:context [(before (vconj! state :before)) | ||
(after (vconj! state :after))]} | ||
(expect (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:before :after] @state))) | ||
(= [:before :expect :after] @state))) | ||
(given [state (volatile! [])] | ||
(it "around" | ||
{:context [(around [f] | ||
(vswap! state conj :before) | ||
(vconj! state :before) | ||
(f) | ||
(vswap! state conj :after))]} | ||
(expect true)) | ||
(vconj! state :after))]} | ||
(expect (vconj! state :expect))) | ||
(expect-it "tracks correctly" | ||
(= [:before :after] @state))))) | ||
(= [:before :expect :after] @state))))) | ||
|
||
(defdescribe propagate-eachs-test | ||
(expect-it "combines correctly" | ||
(= {:context {:before-each [1 2 3 4 5 6] | ||
:after-each []}} | ||
(meta (propagate-eachs {:context {:before-each [1 2 3]}} | ||
(with-meta [] {:context {:before-each [4 5 6]}})))))) | ||
|
||
(defdescribe complex-context-test | ||
(given [state (volatile! [])] | ||
(describe "top level" | ||
{:context [(before (vconj! state :before-top)) | ||
(before-each (vconj! state :before-each-top)) | ||
(after-each (vconj! state :after-each-top)) | ||
(after (vconj! state :after-top))]} | ||
(describe "middle level" | ||
{:context [(before (vconj! state :before-middle)) | ||
(before-each (vconj! state :before-each-middle)) | ||
(after-each (vconj! state :after-each-middle)) | ||
(after (vconj! state :after-middle))]} | ||
(describe "bottom level" | ||
{:context [(before (vconj! state :before-bottom)) | ||
(before-each (vconj! state :before-each-bottom)) | ||
(after-each (vconj! state :after-each-bottom)) | ||
(after (vconj! state :after-bottom))]} | ||
(expect-it "temp 1" (vconj! state :expect-1)) | ||
(expect-it "temp 2" (vconj! state :expect-2))))) | ||
(expect-it "tracks correctly" | ||
(= [:before-top | ||
:before-middle | ||
:before-bottom | ||
:before-each-top | ||
:before-each-middle | ||
:before-each-bottom | ||
:expect-1 | ||
:after-each-bottom | ||
:after-each-middle | ||
:after-each-top | ||
:before-each-top | ||
:before-each-middle | ||
:before-each-bottom | ||
:expect-2 | ||
:after-each-bottom | ||
:after-each-middle | ||
:after-each-top | ||
:after-bottom | ||
:after-middle | ||
:after-top] @state)))) | ||
|
||
(defdescribe multiple-same-eachs-test | ||
(given [state (volatile! [])] | ||
(describe "top level" | ||
{:context [(after-each (vconj! state :after-each-top)) | ||
(after-each (vconj! state :after-each-top-2))]} | ||
(describe "middle level" | ||
{:context [(after-each (vconj! state :after-each-middle)) | ||
(after-each (vconj! state :after-each-middle-2))]} | ||
(describe "bottom level" | ||
{:context [(after-each (vconj! state :after-each-bottom)) | ||
(after-each (vconj! state :after-each-bottom-2))]} | ||
(expect-it "temp 1" (vconj! state :expect-1)) | ||
(expect-it "temp 2" (vconj! state :expect-2))))) | ||
(expect-it "tracks correctly" | ||
(= [:expect-1 | ||
:after-each-bottom | ||
:after-each-bottom-2 | ||
:after-each-middle | ||
:after-each-middle-2 | ||
:after-each-top | ||
:after-each-top-2 | ||
:expect-2 | ||
:after-each-bottom | ||
:after-each-bottom-2 | ||
:after-each-middle | ||
:after-each-middle-2 | ||
:after-each-top | ||
:after-each-top-2] @state)))) |
Oops, something went wrong.