Skip to content

Commit 9fe4c60

Browse files
authored
Flesh out HSpec with basic example (#402)
1 parent b6e4584 commit 9fe4c60

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

content/languages/haskell/hspec.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
---
2-
title: Hspec
32
kind: reference
3+
sidebar: "language:haskell"
4+
prev: /languages/haskell/
5+
languages: [haskell]
6+
tags:
7+
- testing
48
---
9+
10+
# HSpec
11+
12+
## Basic Setup
13+
14+
### Solution Code
15+
16+
```haskell
17+
module Example where
18+
19+
add :: Num a => a -> a -> a
20+
add = (+)
21+
```
22+
23+
### Test Fixture
24+
25+
```haskell
26+
module ExampleSpec where -- test module name MUST end with Spec
27+
import Test.Hspec
28+
import Example
29+
30+
spec :: Spec -- `spec` is required
31+
spec = do
32+
describe "Example" $ do
33+
it "add a b" $ do
34+
(add 1 1) `shouldBe` (2 :: Integer)
35+
36+
main :: IO () -- `main` is optional
37+
main = hspec spec
38+
```

0 commit comments

Comments
 (0)