on master help sign in
inline shouldFail
commitf75c09b556b392cd36155afb9f4cd69e76021ef4 authorMark Wotton <mwotton@gmail.com> dateWed 18 Nov 2020, 16:41 (6 years ago) parent4970e81
3 files changed+28−40
stack.yaml+9−9 stack.yaml.lock+4−30 test/Spec.hs+15−1
stack.yaml+9−9
@@ -1,4 +1,4 @@
1−resolver: lts-16.16
1+resolver: lts-16.8 #lts-16.16
22packages:
33- .
44
@@ -13,11 +13,11 @@ extra-deps:
1313- QuickCheck-2.14.1@sha256:01e46d7b0a8d3148288ec977625f62d5516ebb5031a50c63f0453863301b4a79,7736
1414- random-1.2.0
1515- splitmix-0.1.0.1@sha256:22f9662e7e8b173421872241edd39350078a9ed4bb9e9f503948c5b483c79276,5253
16−- git: https://github.com/hedgehogqa/haskell-hedgehog.git
17− commit: 03714682586e43b5ddf5c00391035471a6e01238
18− subdirs:
19− - hedgehog
20−- git: https://github.com/mwotton/hspec
21− commit: cd9012414a93cf08f86e409544d4d3a8f282b507
22− subdirs:
23− - hspec-core
16+# - git: https://github.com/hedgehogqa/haskell-hedgehog.git
17+# commit: 03714682586e43b5ddf5c00391035471a6e01238
18+# subdirs:
19+# - hedgehog
20+# - git: https://github.com/mwotton/hspec
21+# commit: cd9012414a93cf08f86e409544d4d3a8f282b507
22+# subdirs:
23+# - hspec-core
stack.yaml.lock+4−30
@@ -67,35 +67,9 @@ packages:
6767 sha256: b9a0c60e2d4786bbb276ce6606027a99615bf703fa3e0f01911e8c6a656c5161
6868 original:
6969 hackage: splitmix-0.1.0.1@sha256:22f9662e7e8b173421872241edd39350078a9ed4bb9e9f503948c5b483c79276,5253
70−- completed:
71− subdir: hedgehog
72− name: hedgehog
73− version: 1.0.3
74− git: https://github.com/hedgehogqa/haskell-hedgehog.git
75− pantry-tree:
76− size: 2575
77− sha256: 7e69930fef281dfeb47b2f7c745c26234768e56ffb5490065f607c57146ffbab
78− commit: 03714682586e43b5ddf5c00391035471a6e01238
79− original:
80− subdir: hedgehog
81− git: https://github.com/hedgehogqa/haskell-hedgehog.git
82− commit: 03714682586e43b5ddf5c00391035471a6e01238
83−- completed:
84− subdir: hspec-core
85− name: hspec-core
86− version: 2.7.4
87− git: https://github.com/mwotton/hspec
88− pantry-tree:
89− size: 3899
90− sha256: 6ece11ad28a7f122a502e766eb1b3ef950815c2d16babb0ea8744646f1c1bd70
91− commit: cd9012414a93cf08f86e409544d4d3a8f282b507
92− original:
93− subdir: hspec-core
94− git: https://github.com/mwotton/hspec
95− commit: cd9012414a93cf08f86e409544d4d3a8f282b507
9670snapshots:
9771- completed:
98− size: 532380
99− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/16.yaml
100− sha256: d6b004b095fe2a0b8b14fbc30014ee97e58843b9c9362ddb9244273dda62649e
101− original: lts-16.16
72+ size: 532379
73+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/8.yaml
74+ sha256: 2ad3210d2ad35f3176005d68369a18e4d984517bfaa2caade76f28ed0b2e0521
75+ original: lts-16.8
test/Spec.hs+15−1
@@ -14,7 +14,7 @@ import Data.Dynamic(toDyn)
1414import qualified Roboservant as RS
1515
1616import Test.Hspec
17−import Test.Hspec.Core.Spec(shouldFail)
17+import Test.Hspec.Core.Spec
1818import Data.Void
1919import Data.Maybe
2020
@@ -93,3 +93,17 @@ instance RS.BuildFrom Void
9393
9494instance RS.Breakdown Post.FooPost
9595instance RS.BuildFrom Post.FooPost
96+
97+
98+-- | `shouldFail` allows you to assert that a given `Spec` should contain at least one failing test.
99+-- this is often useful when testing tests.
100+shouldFail :: SpecWith a -> SpecWith a
101+shouldFail = mapSpecItem_ (\i -> i {
102+ itemExample = \p a cb -> do
103+ r <- (itemExample i) p a cb
104+ pure r {resultStatus = case resultStatus r of
105+ Success -> Failure Nothing (Reason "Unexpected success")
106+ Failure _ _ -> Success
107+ x -> x
108+ }
109+ })