hspec-hedgehog
Integrate Hedgehog and Hspec!
https://github.com/hspec/hspec-hedgehog#readme
LTS Haskell 22.41: | 0.1.1.0 |
Stackage Nightly 2024-11-12: | 0.3.0.0 |
Latest on Hackage: | 0.3.0.0 |
hspec-hedgehog-0.3.0.0@sha256:86f70708c4033f22e7e77c2cad864a8b7d64211ac56499e47b4924dcf8a53aaf,1507
Module documentation for 0.3.0.0
- Test
- Test.Hspec
hspec-hedgehog
An integration library for hspec and hedgehog.
Example:
import Control.Concurrent (threadDelay)
import Control.Monad.IO.Class (liftIO)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import Test.Hspec (before, describe, hspec, it, shouldBe)
import Test.Hspec.Hedgehog (PropertyT, diff, forAll, hedgehog,
(/==), (===))
main :: IO ()
main = hspec $ do
describe "regular tests" $ do
it "works" $ do
True `shouldBe` True
describe "hedgehog" $ do
it "is useful if you get an ambiguous error" $ hedgehog $ do
"no ambiguity" === "no ambiguity"
describe "hedgehog tests" $ do
it "lets you use PropertyT directly" $ hedgehog $ do
x <- forAll $ Gen.integral (Range.linear 0 1000)
y <- forAll $ Gen.integral (Range.linear 0 5000)
diff (x + y) (>=) x
it "renders a progress bit" $ hedgehog $ do
x <- forAll $ Gen.integral (Range.linear 0 1000)
y <- forAll $ Gen.integral (Range.linear 1 5000)
liftIO $ threadDelay (100 * x + y)
describe "with hooks" $ do
before (pure "Hello!") $ do
it "has functions" $ \str -> hedgehog $
str === "Hello!"
it "goes before or after" $ \str -> do
pure () :: PropertyT IO ()
str === "Hello!"
it "generates" $ \str -> hedgehog $ do
wrongLen <- forAll $ Gen.integral (Range.linear 0 3)
length str /== wrongLen
How does this differ from hw-hspec-hedgehog
?
Good question!
The hw-spec-hedgehog
implementation does the easy thing.
It calls Hedgehog’s check
function on the property, and if the property returns True
, then it passes the test.
If the property fails, then it renders an uninformative failure message - it’s hardcoded to be:
Hedgehog property test failed
And that’s all you get!
This library preserves Hedgehog’s error message formatting, so you get rich, insightful error messages just like Hedgehog intended.
Furthermore, this library integrates with hspec
’s support for the QuickCheck
library.
Any option that works with QuickCheck
should work with hedgehog
properties, so you can use modifyMaxSuccess (\_ -> 10)
to set the total tests to be 10, rather than the default 100.
Because it integrates directly with hspec, it also renders a familiar progress message while the test is running.
Changes
Changelog for hspec-hedgehog
0.3.0.0
- #45 @ChickenProp
- Set
propertyDiscardLimit
correctly.
- Set
- #44 @ChickenProp
- Don’t re-export
modifyMaxSize
, which is a no-op.
- Don’t re-export
0.2.0.0
- #29 @sol
- Show less context on failure.
0.1.1.0
- #30 @sol
- Show classification on success
- Provide more information on “gave up”
0.1.0.0
- #25 @sol
- Suppress internal source locations.
- #24 @sol
- Regard
--color
/--no-color
.
- Regard
- #23 @ocharles
- Improve type inference by constraining the base monad of
PropertyT
toIO
. This makes explicitly usinghedgehog
redundant in many situations.
- Improve type inference by constraining the base monad of
0.0.1.2
- #7 @parsonsmatt
- Handle error states better by returning them in the instance rather than throwing an exception.
- #6 @jezen
- Bump lower bound on
hedgehog
to fix the build constraints.
- Bump lower bound on
0.0.1.1
- #2 @lehins
- Documentation fix
- #3 @parsonsmatt
- Respect the
maxSuccess
,maxDiscardRatio
, andmaxShrinks
properties of QuickCheck’sArgs
type. - Reexport
modifyArgs
,modifyMaxSuccess
,modifyMaxDiscardRatio
,modifyMaxSize
,modifyMaxShrings
- Respect the
0.0.1.0
- Initial Release