hspec-tables alternatives and similar packages
Based on the "hspec" category.
Alternatively, view hspec-tables alternatives based on common mentions on social networks and blogs.
-
hspec-golden-aeson
Use tests to monitor changes in Aeson serialization -
hspec-expectations-json
Hspec expectations on JSON Values -
hspec-attoparsec
utility functions for testing attoparsec parsers with hspec -
hspec-megaparsec
Utility functions for testing Megaparsec parsers with Hspec -
hspec-hedgehog
Hedgehog support for the Hspec testing framework -
hspec-test-framework
Run test-framework tests with Hspec -
hspec-expectations-match
An hspec expectation that asserts a value matches a pattern -
hspec-expectations-pretty-diff
Catchy combinators for HUnit +++ colored pretty-printed diffs -
hspec-leancheck
LeanCheck support for the Hspec test framework. -
hspec-multicheck
A testing framework for Haskell using Hspec
InfluxDB - Power Real-Time Data Analytics at Scale
Do you think we are missing an alternative of hspec-tables or a related project?
README
hspec-tables
Test.Hspec.Tables
allows you to define table-driven (or, by-example) HSpec tests. For example:
import Test.Hspec
import Test.Hspec.Tables
example1 :: Spec
example1 =
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)
or
example2 :: Spec
example2 =
describe "reverse" $
byExample
("list", "reversed")
[("abc", "cba"), ("", ""), ("0123456", "6543210")]
(shouldBe . reverse)
When you run these, you'll see that each row becomes a seperate test labelled with show row
(so the requirement for rows is to consist of elements that have a Show
instance):
Example specs
multiplication table
("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)
reverse
("list","reversed")
("abc","cba")
("","")
("0123456","6543210")
Finished in 0.0008 seconds
12 examples, 0 failures
The byExample
method is type-safe. The table header must be a 2- to 7- element tuple of String and you must provide the same number of "columns" or it doesn't compile. So if you attempted to write:
example1 :: Spec
example1 =
describe "THIS EXAMPLE DOES NOT COMPILE" $
byExample
("x", "y", "result") -- 3 columns
[ (0, 0, 0, 0) ] -- 4 columns
(\a b c expected -> a * b * c == expected)
then you should get the following error, hopefully guiding to what the problem is
error:
• Couldn't match type ‘([Char], [Char], [Char])’
with ‘(String, String, String, String)’
Expected type: Test.Hspec.Tables.Header
(Integer, Integer, Integer, Integer)
Actual type: ([Char], [Char], [Char])
The assertion function will match the table type, so if your table is of shape (a, b, c)
then the assertion is assumed to be of type (Example e) => a -> b -> c -> e
(ie. it's always curried). Example comes from HSpec
Caveats
- You can define tables up-to 7 columns (adding columns beyond that requires providing an instance of the
Table
type-class)
*Note that all licence references and agreements mentioned in the hspec-tables README section above
are relevant to that project's source code only.