on master help sign in
inline shouldFail
f75c09bMark Wotton
stack.yaml+9−9
@@ -1,4 +1,4 @@
1−resolver: lts-16.16
1+resolver: lts-16.8 #lts-16.16
2packages:
2packages:
3- .
3- .
4
4
@@ -13,11 +13,11 @@ extra-deps:
13- QuickCheck-2.14.1@sha256:01e46d7b0a8d3148288ec977625f62d5516ebb5031a50c63f0453863301b4a79,7736
13- QuickCheck-2.14.1@sha256:01e46d7b0a8d3148288ec977625f62d5516ebb5031a50c63f0453863301b4a79,7736
14- random-1.2.0
14- random-1.2.0
15- splitmix-0.1.0.1@sha256:22f9662e7e8b173421872241edd39350078a9ed4bb9e9f503948c5b483c79276,5253
15- splitmix-0.1.0.1@sha256:22f9662e7e8b173421872241edd39350078a9ed4bb9e9f503948c5b483c79276,5253
16−- git: https://github.com/hedgehogqa/haskell-hedgehog.git
16+# - git: https://github.com/hedgehogqa/haskell-hedgehog.git
17− commit: 03714682586e43b5ddf5c00391035471a6e01238
17+# commit: 03714682586e43b5ddf5c00391035471a6e01238
18− subdirs:
18+# subdirs:
19− - hedgehog
19+# - hedgehog
20−- git: https://github.com/mwotton/hspec
20+# - git: https://github.com/mwotton/hspec
21− commit: cd9012414a93cf08f86e409544d4d3a8f282b507
21+# commit: cd9012414a93cf08f86e409544d4d3a8f282b507
22− subdirs:
22+# subdirs:
23− - hspec-core
23+# - hspec-core
stack.yaml.lock+4−30
@@ -67,35 +67,9 @@ packages:
67 sha256: b9a0c60e2d4786bbb276ce6606027a99615bf703fa3e0f01911e8c6a656c5161
67 sha256: b9a0c60e2d4786bbb276ce6606027a99615bf703fa3e0f01911e8c6a656c5161
68 original:
68 original:
69 hackage: splitmix-0.1.0.1@sha256:22f9662e7e8b173421872241edd39350078a9ed4bb9e9f503948c5b483c79276,5253
69 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
96snapshots:
70snapshots:
97- completed:
71- completed:
98− size: 532380
72+ size: 532379
99− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/16.yaml
73+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/8.yaml
100− sha256: d6b004b095fe2a0b8b14fbc30014ee97e58843b9c9362ddb9244273dda62649e
74+ sha256: 2ad3210d2ad35f3176005d68369a18e4d984517bfaa2caade76f28ed0b2e0521
101− original: lts-16.16
75+ original: lts-16.8
test/Spec.hs+15−1
@@ -14,7 +14,7 @@ import Data.Dynamic(toDyn)
14import qualified Roboservant as RS
14import qualified Roboservant as RS
15
15
16import Test.Hspec
16import Test.Hspec
17−import Test.Hspec.Core.Spec(shouldFail)
17+import Test.Hspec.Core.Spec
18import Data.Void
18import Data.Void
19import Data.Maybe
19import Data.Maybe
20
20
@@ -93,3 +93,17 @@ instance RS.BuildFrom Void
93
93
94instance RS.Breakdown Post.FooPost
94instance RS.Breakdown Post.FooPost
95instance RS.BuildFrom Post.FooPost
95instance 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+ })