Closed kozross closed 4 years ago
The functions in hedgehog-classes
return IO Bool
, where True
indicates that the laws pass. hspec
tests let you run IO
actions in the example blocks.
spec :: Spec
spec = do
describe "Monoid Ordering" $ do
it "satisfies the laws" $ do
result <- lawsCheck (monoidLaws genOrdering)
result `shouldBe` True
You can simplify this to:
it "satisfies the laws" $ do
lawsCheck (monoidLaws genOrdering)
`shouldReturn` True
Or define a helper function:
hedgeLaws :: String -> IO Bool -> IO ()
hedgeLaws message action =
it message $
action `shouldReturn` Bool
spec :: Spec
spec = do
describe "Monoid ordering" $ do
hedgeLaws "works" $ monoidLaws genOrdering
It's not immediately apparent to me how I could use this to test various type class laws in Hspec. Would some support be possible?