Also, you can import Test.Hspec.Monadic rather than Test.Hspec if you want to use a WriterMonad based api.
http://hackage.haskell.org/package/hspechttps://github.com/trystan/hspecAs always, any advice, comments, or questions are welcome,
Trystan Spangler
For those who would like to see an example, using the new alternate monadic api, running this program:
import Test.Hspec.Monadic
import Test.Hspec.HUnit
import Test.Hspec.QuickCheck (property)
import Test.HUnit (assertBool, assertEqual)
main = hspec specs
specs = describe "hspec 0.4.3" $ do
it "still allows a Bool expression to act as an example"
(replicate 5 1 == [1,1,1,1,1])
it "still allows HUnit assertions to act as examples"
(assertBool "lame example" True)
it "still allows QuickCheck properties to act as examples"
(property $ \ i -> (i::Int) == i + 1 - 1)
it "still shows a list of failed examples"
(undefined :: Bool) -- expected to fail
it "still collects better data from failed HUnit examples"
(assertEqual "this should fail" 1 2) -- expected to fail
it "still collects better data from failed QuickCheck examples"
(property $ \ i -> (i::Int) * 2 - 2 /= i) -- expected to fail
it "now allows a monadic api"
(pending "I'm still not sure how to test this but this example is good evidence....")
it "now outputs in color when writing to stdout"
(pending "I'm still not sure how to test this but trust me it works....")
should send this to stdout in glorious red, yellow, and green:
hspec 0.4.3
- still allows a Bool expression to act as an example
- still allows HUnit assertions to act as examples
- still allows QuickCheck properties to act as examples
x still shows a list of failed examples FAILED [1]
x still collects better data from failed HUnit examples FAILED [2]
x still collects better data from failed QuickCheck examples FAILED [3]
- now allows a monadic api
# I'm still not sure how to test this but this example is good evidence....
- now outputs in color when writing to stdout
# I'm still not sure how to test this but trust me it works....
1) hspec 0.4.3 still shows a list of failed examples FAILED
Prelude.undefined
2) hspec 0.4.3 still collects better data from failed HUnit examples FAILED
this should fail
expected: 1
but got: 2
3) hspec 0.4.3 still collects better data from failed QuickCheck examples FAILED
*** Failed! Falsifiable (after 6 tests):
2
Finished in 0.0520 seconds
8 examples, 3 failures