-
Notifications
You must be signed in to change notification settings - Fork 2
/
before-run-hook.html
100 lines (86 loc) · 5.23 KB
/
before-run-hook.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Expectations by jaycfields</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<script src="javascripts/scale.fix.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<header>
<h1 class="header">Expectations</h1>
<p class="header">a minimalist's unit testing framework</p>
<ul>
<li><a class="buttons" href="index.html">Home</a></li>
<li><a class="buttons" href="installing.html">Installing</a></li>
<li><a class="buttons" href="introduction.html">Introduction</a></li>
<li><a class="buttons" href="advanced.html">Advanced</a></li>
<li><a class="buttons" href="collections.html">Collections</a></li>
<li><a class="buttons" href="templating.html">Expect More</a></li>
<li><a class="buttons" href="odds-ends.html">Odds & Ends</a></li>
<li><a class="buttons" href="in-context.html">Around Each</a></li>
<li><a class="buttons" href="before-run-hook.html">Around Suite</a></li>
<li><a class="buttons" href="state-warnings.html">State Warnings</a></li>
<li><a class="buttons" href="redef-state.html">Redef State</a></li>
<li><a class="buttons" href="interactions.html">Side Effects</a></li>
<li><a class="buttons" href="freeze-time.html">Freeze Time</a></li>
<li><a class="buttons" href="env-tweaks.html">ENV Tweaks</a></li>
<li><a class="buttons" href="emacs-tweaks.html">emacs Tweaks</a></li>
<li><a class="buttons" href="clojure-test.html">clojure.test</a></li>
<li><a class="buttons github" href="https://github.com/clojure-expectations/expectations">View On GitHub</a></li>
</ul>
<p class="header">This project is maintained by <a class="header name" href="https://github.com/seancorfield">seancorfield</a> and <a class="header name" href="https://github.com/jaycfields">jaycfields</a></p>
</header>
<section>
<h1>
<a name="expectations" class="anchor" href="#expectations"><span class="octicon octicon-link"></span></a>expectations</h1>
<blockquote>
<p>adding signal, removing noise</p>
</blockquote>
<h2>
<a name="beforerun" class="anchor" href="#beforerun"><span class="octicon octicon-link"></span></a>Run Custom Functions Before Running the Test Suite</h2>
As of version 1.4.24, expectations will execute any function that includes the following metadata <code>{:expectations-options :before-run}</code>, before starting to execute the test suite.
<br><br>
There are several reasons that you might want to call a custom function before the test suite is executed-<ul>
<li>load sample data to a database
<li>delete a temp directory
<li>replace logging with standard out or /dev/null</ul>
<br>
The following example should serve as a decent reference on how to add your own 'before-run' functions.
<br><br>
<script src="https://gist.github.com/4401091.js"></script>
<br>
<h2>
<a name="afterrun" class="anchor" href="#afterrun"><span class="octicon octicon-link"></span></a>Run Custom Functions After Completing the Test Suite</h2>
As of version 1.4.48, expectations will execute any function that includes the following metadata <code>{:expectations-options :after-run}</code>, after executing the test suite.
<br><br>
This can be used to clean up resources and shut down executors or other services after the test suite has completed.
<h2>
<a name="options" class="anchor" href="#options"><span class="octicon octicon-link"></span></a>expectations-options</h2>
These functions can be defined anywhere; however, expectations looks in a default location for a configuration file.
If expectations finds this configuration file it removes (what should be) the namespace and requires it with <code>:reload</code>.
As a result, this configuration namespace will be removed and redefined with each expectations suite run.
<br><br>
The name of this default configuration file is <code>expectations_options.clj</code> (thus the namespace is <code>expectations-options</code>).
Expectations looks for this file in the root test directory. If you have <code>:test-paths ["test/clojure"]</code> in your <code>project.clj</code>,
then you'll want to create <code>test/clojure/expectations_options.clj</code>.
<br><br>
If you place your expectations_options.clj file in the correct location and you add the <code>{:expectations-options :before-run}</code>
or <code>{:expectations-options :after-run}</code>
metadata to a function in the expectations-options namespace, your function should be run automatically the next time your test suite runs.
You may want to start with a <code>(println)</code> just to verify that things are going as you expect.
</section>
<footer>
<p><small>Hosted on <a href="https://pages.github.com">GitHub Pages</a> using the Dinky theme</small></p>
</footer>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</html>