| Copyright | (c) 2020 Marcin Rzeźnicki |
|---|---|
| License | MIT |
| Maintainer | Marcin Rzeźnicki <marcin.rzeznicki@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Test.Hspec.Tables
Description
Table-driven (by-example) HSpec tests.
Example usage:
describe "multiplication table" $
byExample
("x", "y", "result")
[ (0, 0, 0),
(0, 1, 0),
(0, 2, 0),
(1, 0, 0),
(1, 1, 1),
(1, 2, 2),
(2, 0, 0),
(2, 1, 2),
(2, 2, 4)
]
(\a b expected -> a * b == expected)describe "reverse" $
byExample
("list", "reversed")
[("abc", "cba"), ("", ""), ("0123456", "6543210")]
(shouldBe . reverse)Documentation
A type class for tables.
A table type binds together the row type r with the type of its header and the "generic" curried function forall p. r -> p
Minimal complete definition
Methods
apply :: Forall r p -> r -> p Source #
showHeader :: Header r -> String Source #
default showHeader :: Show (Header r) => Header r -> String Source #
Arguments
| :: forall a r. (Table r, Example a, Show r) | |
| => Header r | header - tuple of strings (max 7 for now); used to |
| -> [r] | rows - list of tuples of examples; arity of each tuple must match the number of columns (== arity of the header) |
| -> Forall r a | assertion - curried function from a row to an |
| -> SpecWith (Arg a) |
Creates a Spec from the table consisting of:
- header
- list of examples (rows)
- assertion
The resulting spec consists of one test per each row. For example:
byExample
("list", "reversed")
[("abc", "cba"), ("", ""), ("0123456", "6543210")]
(shouldBe . reverse)is equivalent to:
describe (show ("list", "reversed")) $ do
specify (show ("abc", "cba")) $ reverse "abc" `shouldBe` "cba"
specify (show ("", "")) $ reverse "" `shouldBe` ""
specify (show ("0123456", "6543210")) $ reverse "0123456" `shouldBe` "6543210"