Skip to content
DannoHung edited this page Sep 13, 2010 · 12 revisions

There are three helper functions provided to make any setup and teardown activities needed for your tests less repetitive: before, after, and alt.

before and after

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

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

.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.

In this example, there is a file text.txt in the same directory as the test file you are loading:


file:.tst.testFilePath `text.txt
read0 file

Currently, it is not loaded into a main namespace because it is under evaluation.

Clone this wiki locally