├── .gitignore
├── 00_hello
├── HelloSpec.js
└── index.html
├── 01_properties
├── index.html
└── propertiesSpec.js
├── 02_loops
├── LoopsSpec.js
└── index.html
├── 03_calculator
├── calculatorSpec.js
└── index.html
├── 04_temperature
├── index.html
├── matchers.js
└── temperatureSpec.js
├── 05_dom
├── colorSpec.js
├── domSpec.js
├── domTemperatureWidgetSpec.js
├── index.html
├── numberSpec.js
└── temperatureDemo.html
├── 06_bouncing_ball
├── bouncingBallSpec.js
└── index.html
├── Gemfile
├── Gemfile.lock
├── Rakefile
├── abstract.txt
├── assets
└── style.css
├── index.html
├── jasmine.yml
└── todo.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
--------------------------------------------------------------------------------
/00_hello/HelloSpec.js:
--------------------------------------------------------------------------------
1 | describe("Hello", function() {
2 | it("says hello", function() {
3 | expect(hello()).toEqual("Hello!");
4 | });
5 |
6 | it("says hello to someone", function() {
7 | expect(hello("Fred")).toEqual("Hello, Fred!");
8 | });
9 | });
10 |
11 |
--------------------------------------------------------------------------------
/00_hello/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Say Hello to JavaScript
26 |
27 |
Open a console
28 |
29 |
Once the console is open, change directories into the 00_hello directory
30 |
31 |
cd 00_hello
32 |
33 |
34 |
Run the Jasmine server
35 |
36 |
rake jasmine
37 |
38 |
39 |
Open the spec page in your web browser
40 |
41 |
open http://localhost:8888/ # Mac only
42 |
43 |
44 |
You should see a failing spec. This is good! Now it's your turn to make it pass.
45 |
46 |
Open the spec file in a text editor
47 |
48 |
open HelloSpec.js # Mac only
49 |
50 |
51 |
This file is written in a particular syntax for a testing tool named Jasmine BDD. Here are a few important rules:
52 |
53 |
54 | - each "
describe
" starts a related group of specs
55 | - each "
it
" starts a single spec
56 | - each "
expect
" describes a single assertion about your source code
57 |
58 |
59 |
60 |
For example, expect(hello()).toEqual("Hello!")
means "when I call the function hello()
, I expect its result to be equal to the string "Hello!"
"
61 |
62 |
Create the source file
63 |
64 |
Create and open a file named hello.js
. Inside it, put the following text:
65 |
66 |
function hello() {
67 | }
68 |
69 |
70 |
Reload the spec page in the browser
71 |
72 |
You should still see the same failing spec, but it should be failing for a different reason.
73 |
74 |
Make the first spec pass
75 |
76 |
Make hello.js
look like this:
77 |
78 |
function hello() {
79 | return "Hello!"
80 | }
81 |
82 |
83 |
Reload the spec page in the browser. The first spec should pass!
84 |
85 |
Now do a little victory dance!
86 |
87 |
Also, high five your partner. If you don't have a partner, high five your dog.
88 |
89 |
Next steps
90 |
91 |
Make the next spec pass. This will require an if
statement and some messing around with the function declaration.
92 |
93 |
Here's a hint: In JavaScript, if the caller forgets to pass in an argument to a function, then its value is undefined (which is almost the same thing as false).
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/01_properties/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Learn JavaScript Test-First
26 |
27 |
Setup
28 |
29 |
Welcome!
30 |
31 |
38 |
39 |
40 |
Install Ruby
41 |
42 |
First check if you have ruby already. Try this:
43 |
44 |
ruby -v
45 |
46 |
47 |
If the response is something like this
48 |
49 |
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
50 |
51 |
52 |
then skip ahead.
53 |
54 |
Otherwise...
55 |
56 |
60 |
61 |
62 |
Install Jasmine
63 |
64 |
Jasmine is a JavaScript testing framework. While Jasmine can be run from a plain HTML file, we are using the Jasmine Server, which comes as a "gem" (a Ruby program).
65 |
66 |
gem install jasmine
67 |
68 |
69 |
Learning
70 |
71 |
Your course directory has a list of lab directories. Each directory has a spec file. You will write all the code to make all the specs in it pass.
72 |
73 |
To get your feet wet in this process, go into the "hello" lab with cd 00_hello
and read the detailed instructions in its index.html
file.
74 |
75 |
Once you got through "hello", then congratulations! Now it's time to go to the
76 | next directory (whose name begins with 01_
) and start learning JavaScript!
77 |
78 |
Problems? Questions?
79 |
80 |
First, ask your neighbor. Then, ask your instructor.
81 |
82 |
Then ask Google (seriously!). If there's an error, try copying the error string and pasting it into a Google search box. If that doesn't help, do a search on one of these sites:
83 |
84 |
87 |
88 |
89 |
You can also find help at the TestFirst.org site or the Test-First Teaching mailing list.
90 |
91 |
Resources
92 |
93 |
114 |
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/jasmine.yml:
--------------------------------------------------------------------------------
1 | src_dir: .
2 |
3 | # all files, including specs, are included as src_files
4 | src_files:
5 | - '**/*.js'
6 | - '../helpers/**/*.js'
7 | - 'helpers/**/*.js'
8 |
9 | # in order to remove duplicates, specify a nonexistent dir for specs
10 | spec_dir: nada
11 |
12 |
--------------------------------------------------------------------------------
/todo.txt:
--------------------------------------------------------------------------------
1 | * make git repo generator work
2 | * make 'rake jasmine:ci' work (may need to fix rspec gem version bug in Jasmine)
3 | * use custom runner
4 | * 'show passed' on by default
5 | * stop after first failure
6 | * figure out how to get common helpers (Jasmine doesn't like my file layout)
7 |
8 |
--------------------------------------------------------------------------------