Skip to content

Commit 0ec577f

Browse files
committed
Add jasmine.
1 parent aa4c552 commit 0ec577f

11 files changed

+3520
-4
lines changed

SpecRunner.html

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2+
"http://www.w3.org/TR/html4/loose.dtd">
3+
<html>
4+
<head>
5+
<title>Jasmine Spec Runner</title>
6+
7+
<link rel="stylesheet" type="text/css" href="vendors/jasmine/jasmine.css">
8+
<script src="vendors/jasmine/jasmine.js" type="text/javascript"></script>
9+
<script src="vendors/jasmine/jasmine-html.js" type="text/javascript"></script>
10+
<script src="vendors/sugar-1.3.min.js" type="text/javascript"></script>
11+
<script src="vendors/underscore.js" type="text/javascript"></script>
12+
<script src="vendors/YouAreDaBomb.js" type="text/javascript"></script>
13+
<script src="vendors/jquery-1.7.2.min.js" type="text/javascript"></script>
14+
15+
<script src="release/spec-debug.js" type="text/javascript"></script>
16+
17+
<script type="text/javascript">
18+
(function() {
19+
var jasmineEnv = jasmine.getEnv();
20+
jasmineEnv.updateInterval = 1000;
21+
22+
var htmlReporter = new jasmine.HtmlReporter();
23+
24+
jasmineEnv.addReporter(htmlReporter);
25+
26+
jasmineEnv.specFilter = function(spec) {
27+
return htmlReporter.specFilter(spec);
28+
};
29+
30+
var currentWindowOnload = window.onload;
31+
32+
window.onload = function() {
33+
if (currentWindowOnload) {
34+
currentWindowOnload();
35+
}
36+
execJasmine();
37+
};
38+
39+
function execJasmine() {
40+
jasmineEnv.execute();
41+
}
42+
43+
})();
44+
</script>
45+
46+
</head>
47+
48+
<body>
49+
</body>
50+
</html>

index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<link rel="stylesheet" href="css/base.css">
88
</head>
99
<body>
10-
<div data-element="main" class="main">
11-
</div>
10+
<div data-element="main" class="main"></div>
1211

1312
<script type="x-handlebars-template" id="timer-template">
1413
<div data-element="timer">

src/blind_collection.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ class BlindCollection
1010

1111
current: =>
1212
@blinds[@currentIndex]
13+
14+
indexOf: (blind) =>
15+
@blinds.indexOf(blind)

src/spec/clock_spec.coffee

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#<< clock
2+
3+
describe "Clock", ->
4+
describe "new", ->
5+
beforeEach =>
6+
@clock = new Clock()
7+
8+
it "elapsed 0 seconds", =>
9+
expect(@clock.seconds()).toBe(0)
10+
11+
it "elapsed 0 minutes", =>
12+
expect(@clock.minutes()).toBe(0)
13+
14+
it "is 00:00 as a string", =>
15+
expect(@clock.toString()).toBe('00:00')
16+
17+
describe "after elapsing 30 seconds", ->
18+
beforeEach =>
19+
@clock = new Clock()
20+
30.times =>
21+
@clock.addSecond()
22+
23+
it "elapsed 30 seconds", =>
24+
expect(@clock.seconds()).toBe(30)
25+
26+
it "elapsed 0 minutes", =>
27+
expect(@clock.minutes()).toBe(0)
28+
29+
it "is 00:30 as a string", =>
30+
expect(@clock.toString()).toBe('00:30')

src/spec/use_case_spec.coffee

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#<< use_case
2+
#<< clock
3+
#<< blind
4+
5+
describe 'UseCase', ->
6+
beforeEach =>
7+
@clock = new Clock()
8+
@useCase = new UseCase(@clock)
9+
10+
it "resets clock on start", =>
11+
spyOn(@clock, 'reset')
12+
@useCase.start()
13+
expect(@clock.reset).toHaveBeenCalled()
14+
15+
it "adds a blind", =>
16+
blind = new Blind(10, 20)
17+
@useCase.blindAdded(blind)
18+
expect(@useCase.blinds).toContain(blind)
19+
20+
describe 'when time changed', =>
21+
22+
it 'adds one second to clock', =>
23+
spyOn(@clock, 'addSecond')
24+
@useCase.secondElapsed()
25+
expect(@clock.addSecond).toHaveBeenCalled()
26+
27+
it 'does not switch to next round until current has finished', =>
28+
spyOn(@useCase, 'switchToNextRound')
29+
@useCase.setRoundLength(3)
30+
2.times @useCase.secondElapsed
31+
expect(@useCase.switchToNextRound).not.toHaveBeenCalled()
32+
33+
it 'switches to next round if current round has finished', =>
34+
spyOn(@useCase, 'switchToNextRound')
35+
@useCase.setRoundLength(3)
36+
3.times @useCase.secondElapsed
37+
expect(@useCase.switchToNextRound).toHaveBeenCalled()
38+
39+
describe 'switch to next round', =>
40+
41+
it 'resets clock', =>
42+
spyOn(@clock, 'reset')
43+
@useCase.switchToNextRound()
44+
expect(@clock.reset).toHaveBeenCalled()
45+
46+
it 'increases blinds', =>
47+
oldBlind = @useCase.currentBlind()
48+
@useCase.switchToNextRound()
49+
newBlind = @useCase.currentBlind()
50+
expect(newBlind.big).toBeGreaterThan(oldBlind.big)
51+

src/use_case.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class UseCase
1515
start: =>
1616
@clock.reset()
1717

18+
setRoundLength: (@roundLengthInSeconds) =>
19+
1820
blindAdded: (blind) =>
1921
@blinds.add(blind)
2022

toaster.coffee

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# => SRC FOLDER
22
toast 'src'
33

4-
# EXCLUDED FOLDERS (optional)
5-
# exclude: ['folder/to/exclude', 'another/folder/to/exclude', ... ]
4+
exclude: ['src/spec']
65

76
# => VENDORS (optional)
87
# vendors: ['vendors/underscore.js']

toaster_spec.coffee

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# KILL ME PLEASE
2+
toast 'src'
3+
4+
# EXCLUDED FOLDERS (optional)
5+
exclude: ['src/app']
6+
7+
# => VENDORS (optional)
8+
# vendors: ['vendors/underscore.js']
9+
10+
# => OPTIONS (optional, default values listed)
11+
bare: true
12+
packaging: true
13+
# expose: ''
14+
# minify: true
15+
16+
# => HTTPFOLDER (optional), RELEASE / DEBUG (required)
17+
httpfolder: 'release'
18+
release: 'release/spec.js'
19+
debug: 'release/spec-debug.js'

0 commit comments

Comments
 (0)