hspec-hedgehog-0.0.1.2: Integrate Hedgehog and Hspec!

Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Hedgehog

Contents

Description

This module allows you to easily integrate the Hedgehog library with Test.Hspec test-suites.

To get started, check out the hedgehog function, which lets you embed a PropertyT directly.

spec :: Spec
spec =
  describe "my great test" $ do
    it "generates stuff" $
      hedgehog $ do
        a <- forAll generator
        a === expected

Truth be told, the functionality is in the two orphan instances of Example for PropertyT. You can directly use code in the PropertyT IO type. However, because most Hedgehog functions are abstract in MonadTest, you might get errors about ambiguous types. The hedgehog function fixes the type to PropertyT IO '()', which works out just fine.

You can use all of hspec's hooks with this, of course.

spec :: Spec
spec = before (pure "Hello!") $ do
  describe "with a string" $ do
    it "gets a string" $ \ str ->
      hedgehog $ do
        wrongLen <- forAll $ integral (linear 0 3)
        length str /== wrongLen

The function before will make all the following spec items a function, accepting that as a parameter. You should call hedgehog after the lambda.

If you are morally opposed to the pattern:

it "message" $ hedgehog $ do
  True === False

Then you can alternatively force the type some other way. One option is to use a no-op function, like this:

it "message" $ do
  pure () :: PropertyT IO ()
  True === False

This style has the advantage that parameters via hooks are less difficult to get right.

before (pure "Hello!") $ do
  it "message" $ \str -> do
    pure () :: PropertyT IO ()
    wrongLen <- forAll $ integral (linear 0 3)
    length str /== wrongLen

You don't have to remember to put the hedgehog call after the lambda.

Synopsis

The Main Function

hedgehog :: HasCallStack => PropertyT IO () -> PropertyT IO () Source #

Embed a Hedgehog PropertyT IO () in an hspec test.

spec :: Spec
spec =
  describe "my great test" $ do
    it "generates stuff" $
      hedgehog $ do
        a <- forAll generator
        a === expected

This function is only used to fix the type of the PropertyT monad transformer. The functions in Hedgehog are typically abstract in a MonadTest, and it's easy to get ambiguous type errors if you leave this out.

Since: 0.0.0.0

Hspec re-exports

modifyArgs :: (Args -> Args) -> SpecWith a -> SpecWith a #

Use modified Args for given spec.

modifyMaxSuccess :: (Int -> Int) -> SpecWith a -> SpecWith a #

Use a modified maxSuccess for given spec.

modifyMaxDiscardRatio :: (Int -> Int) -> SpecWith a -> SpecWith a #

Use a modified maxDiscardRatio for given spec.

modifyMaxSize :: (Int -> Int) -> SpecWith a -> SpecWith a #

Use a modified maxSize for given spec.

modifyMaxShrinks :: (Int -> Int) -> SpecWith a -> SpecWith a #

Use a modified maxShrinks for given spec.

Hedgehog Re-exports

module Hedgehog

Orphan instances

Example (a -> PropertyT IO ()) Source #

Warning: orphan instance! This instance is used to embed a Hedgehog property seamlessly into the hspec framework.

The instance will pick things up from the Test.Hspec.QuickCheck configuration. For example, if the program is supposed to use a predetermined seed, then the same seed will be used for QuickCheck and Hedgehog tests.

Since: 0.0.0.0

Instance details

Associated Types

type Arg (a -> PropertyT IO ()) :: Type #

Methods

evaluateExample :: (a -> PropertyT IO ()) -> Params -> (ActionWith (Arg (a -> PropertyT IO ())) -> IO ()) -> ProgressCallback -> IO Result #

Example (PropertyT IO ()) Source #

Warning: Orphan instance! This instance is used to embed a Hedgehog property seamlessly into the hspec framework. See the other instance of Example for a function for more details.

Since: 0.0.0.0

Instance details

Associated Types

type Arg (PropertyT IO ()) :: Type #