Skip to content

Commit 6000865

Browse files
committed
Minor wording changes to Jasmine test recipe.
1 parent 341ff7b commit 6000865

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

chapters/testing/testing_with_jasmine.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ chapter: Testing
55
---
66
## Problem
77

8-
You are writing a new calculator library using CoffeeScript code and you want to verify it functions as expected. You decide to use the <a href="http://pivotal.github.com/jasmine/" target="_blank">Jasmine</a> test framework.
8+
You are writing a simple calculator using CoffeeScript and you want to verify it functions as expected. You decide to use the <a href="http://pivotal.github.com/jasmine/" target="_blank">Jasmine</a> test framework.
99

1010
## Discussion
1111

12-
When using the Jasmine test framework, you write tests in a spec that describe the expected functionality of the code to be tested.
12+
When using the Jasmine test framework, you write tests in a specification (spec) file that describes the expected functionality of the code to be tested.
1313

14-
For example, we expect our calculator will be able to add and subtract both positive and negative numbers correctly. Our spec is listed below.
14+
For example, we expect our calculator will be able to add and subtract and will function correctly with both positive and negative numbers. Our spec is listed below.
1515

1616
{% highlight coffeescript %}
1717

@@ -45,10 +45,10 @@ describe 'Calculator', ->
4545
### Configuring Jasmine
4646

4747
Before you can run your tests, you must download and configure Jasmine. This involves:
48-
1. Download the latest <a href="http://pivotal.github.com/jasmine/download.html" target="_blank">Jasmine</a> zip file
49-
2. Create a spec and a spec/jasmine folder in your project
50-
3. Extract the Jasmine files into the spec/jasmine folder
51-
4. Create a test runner
48+
1. downloading the latest <a href="http://pivotal.github.com/jasmine/download.html" target="_blank">Jasmine</a> zip file;
49+
2. creating a spec and a spec/jasmine folder in your project;
50+
3. extracting the downloaded Jasmine files into the spec/jasmine folder; and
51+
4. creating a test runner.
5252

5353
### Create a Test Runner
5454

@@ -114,15 +114,15 @@ This spec runner can be downloaded from this GitHub <a href="https://gist.github
114114

115115
To use the SpecRunner.html, simply reference your compiled JavaScript files and compiled tests after jasmine.js and its dependencies.
116116

117-
In the example, you can see we include our yet-to-be-developed calculator.js file (line 14) and the our compiled calculatorSpec.js file (line 17).
117+
In the above example, we include our yet-to-be-developed calculator.js file on line 14 and our compiled calculatorSpec.js file on line 17.
118118

119119
## <span style="color: red;">Running the Tests</span>
120120

121-
To run our tests, simply open SpecRunner.html in a web browser. In this example we see 4 failing specs with a total of 8 failures (below).
121+
To run our tests, simply open SpecRunner.html in a web browser. In our example we see 4 failing specs with a total of 8 failures (below).
122122

123123
<img src="images/jasmine_failing_all.jpg" alt="All failing tests" />
124124

125-
It appears our tests are failing because Jasmine can not find the variable Calculator. That's because it has not been created yet. Let's do that now in a new file named js/calculator.coffee.
125+
It appears our tests are failing because Jasmine can not find the variable Calculator. That's because it has not been created yet. Let's do that now by creating a new file named js/calculator.coffee.
126126

127127

128128
{% highlight coffeescript %}
@@ -133,11 +133,11 @@ window.Calculator = class Calculator
133133

134134
{% endhighlight %}
135135

136-
When we re-run we see the following.
136+
Compile calculator.coffee and refresh the browser to re-run the test suite.
137137

138138
<img src="images/jasmine_failing_better.jpg" alt="Still failing, but better" />
139139

140-
We now have 4 failures instead of our previous 8. That's a 50% improvment with 1 line of code. Not bad.
140+
We now have 4 failures instead of our previous 8. That's a 50% improvment with only one line of code.
141141

142142
## <span style="color: green;">Getting the Tests to Pass</span>
143143

@@ -163,7 +163,7 @@ When we refresh we see they all pass.
163163

164164
## <span style="color: green;">Refactoring the Tests</span>
165165

166-
Now that our tests pass, we should look to see if our code or our test(s) can be refactored. In our spec file, each test creates its own calculator instance. This can make our tests quite repetitive especially for larger test suites. Ideally, we should consider moving that initializaton code into a routine that runs before each test.
166+
Now that our tests pass, we should look to see if our code or our test(s) can be refactored. In our spec file, each test creates its own calculator instance. This can make our tests quite repetitive especially for larger test suites. Ideally, we should consider moving that initializaton code into a routine that runs before each test. Luckily Jasmine has a beforeEach function just for this purpose.
167167

168168
{% highlight coffeescript %}
169169

0 commit comments

Comments
 (0)