-
Notifications
You must be signed in to change notification settings - Fork 2
/
state-warnings.html
84 lines (74 loc) · 4.71 KB
/
state-warnings.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
<!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="statewarn" class="anchor" href="#statewarn"><span class="octicon octicon-link"></span></a>Warn on Unexpected State Changes</h2>
While writing tests it can be easy to accidentally change any global state that exists in your application.
The next section, <a href="redef-state.html">Redefining State Within a Test</a>, gives you an easy way to redefine all state; however, <code>redef-state</code> and <code>with-redefs</code> only help you if you redefine all of the affected state.
The situation is even more problematic due to the fact that accidental state alteration often doesn't cause issues until a completely unrelated test suddenly fails.
After being bitten by this issue a few times, I added the ability to warn when global state is modified by a test.
<br><br>
As of version 1.4.24 if you add <code>(expectations/warn-on-iref-updates)</code> anywhere, expectations will provide you with a warning whenever any global state is altered.
<br><br>
While you can add that snippet anywhere, I prefer to add it to the <code>:before-run</code> hook described in <a href="before-run-hook.html">this section</a>.
There's an example <code><a href="https://github.com/clojure-expectations/expectations/blob/master/test/clojure/expectations_options.clj">expectations_options.clj</a></code>
in the expectations codebase that shows all of the code you need to enable this feature.
Simply add this file or add the function to your existing file and you should see a warning on any global state alteration.
If you're not sure where to put this file, refer to <a href="before-run-hook.html">this section</a>.
<br><br>
Here's an example warning (generated by running the expectations tests).
<br>
<pre>WARNING: success.success-examples:280 modified
#'success.success-examples-src/an-atom from "atom" to "another atom"</pre>
The warning should let you know which test is doing an unexpected modification, and the to and from values should give you an idea of where in the source the alteration is occurring.
</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>