-
Notifications
You must be signed in to change notification settings - Fork 10
Helpers
There are three helper functions provided to make any setup and teardown activities needed for your tests less repetitive: before
, after
, and alt
.
Both before
and after
are very simple. They are both monadic functions that take a function and execute their argument. They will each run before and after an individual expectation (as their names would imply). In the case of fuzz expectations, they do not run before and after each individual test run, but rather before and after all of the test runs (ie: once). You can use any function within the before
and after
statements; using @must@ is discouraged though as it can be confusing and failed assertions in before
and after
statements may be ignored.
See the example below
alt
is a simple way of providing an alternative context for before
and after
as you may want to have several tests within the same specification that require different pre and post-requisites.
.tst.desc["Some Object"]{
before {`foo mock 1};
should["have this behavior"]{...} / In this expectation, foo will have a value of 1
alt{
before {`foo mock 2};
should["have this other behavior"]{...} / In this expectation, foo will have a value of 2
};
should["have a final behavior"]{...} / In this expectation, foo will have a value of 1
}
.tst.testFilePath
is a convenience function for getting hsym’s to file relative to the directory that a test was loaded from. You can use this to load data files for tests that aren’t quite fixtures for example.