<commit_before>---
layout: default
title: Using QuickCheck with Hspec
---

You can use arbitrary QuickCheck properties with Hspec, but they must be of
type {{'Property'|id}}.  QuickCheck's {{'property'|id}} function can be used to
turn anything that is a member of the {{'Testable'|id}} class into a
{{'Property'|id}}.  Here is an example:

```hspec
describe "read" $ do
  it "is inverse to show" $ property $
    \x -> (read . show) x == (x :: Int)
```

{% example QuickCheck.hs %}
<commit_msg>Add docs on how to configure the quickcheck driver<commit_after>---
layout: default
title: Using QuickCheck with Hspec
---

You can use arbitrary QuickCheck properties with Hspec, but they must be of
type {{'Property'|id}}.  QuickCheck's {{'property'|id}} function can be used to
turn anything that is a member of the {{'Testable'|id}} class into a
{{'Property'|id}}.  Here is an example:

```hspec
describe "read" $ do
  it "is inverse to show" $ property $
    \x -> (read . show) x == (x :: Int)
```

{% example QuickCheck.hs %}

It's also possible to modify some of the arguments passed to the Quickcheck
driver, namely: the maximum number of successes before succeeding, the maximum
number of discarded tests per successful test before giving up and size of
the test case:

```hspec
import Test.Hspec.Core.QuickCheck (modifyMaxSize)

describe "read" $ do
  modifyMaxSize (const 1000) $ it "is inverse to show" $ property $
    \x -> (read . show) x == (x :: Int)
```

{'fraction_non_alphanumeric': 0.12678936605316973, 'fraction_numerical': 0.0027266530334014998, 'mean_word_length': 4.010238907849829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3258512', 'n_tokens_mistral': 466, 'n_tokens_neox': 438, 'n_words': 200}