Created
January 10, 2012 16:36
-
-
Save danscotton/1589914 to your computer and use it in GitHub Desktop.
Jasmine specs for new game timer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Timer", -> | |
beforeEach -> | |
@timer = new Timer() | |
describe "a new instance", -> | |
it "should return 0 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(0) | |
it "should return '0' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('0') | |
it "should return 0 for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('00') | |
describe "start()", -> | |
beforeEach -> | |
@clock = sinon.useFakeTimers() | |
@timer.start() | |
afterEach -> | |
@clock.restore() | |
describe "after 1 second", -> | |
beforeEach -> | |
@clock.tick(1000) | |
it "should return 1 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(1) | |
it "should return '0' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('0') | |
it "should return '01' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('01') | |
describe "after 2 seconds", -> | |
beforeEach -> | |
@clock.tick(2000) | |
it "should return 2 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(2) | |
it "should return '0' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('0') | |
it "should return '02' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('02') | |
describe "after 60 seconds (1:00)", -> | |
beforeEach -> | |
@clock.tick(60000) | |
it "should return 60 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(60) | |
it "should return '1' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('1') | |
it "should return '00' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('00') | |
describe "after 68 seconds (1:08)", -> | |
beforeEach -> | |
@clock.tick(68000) | |
it "should return 68 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(68) | |
it "should return '1' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('1') | |
it "should return '08' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('08') | |
describe "after 183 seconds (3:03)", -> | |
beforeEach -> | |
@clock.tick(183000) | |
it "should return 183 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(183) | |
it "should return '3' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('3') | |
it "should return '03' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('03') | |
describe "reset() the timer after 10 seconds", -> | |
beforeEach -> | |
@clock = sinon.useFakeTimers() | |
@timer.start() | |
@clock.tick(10000) | |
@timer.reset() | |
afterEach -> | |
@clock.restore() | |
it "should return 0 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(0) | |
it "should return '0' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('0') | |
it "should return '00' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('00') | |
describe "stop() the timer after 5 seconds", -> | |
beforeEach -> | |
@clock = sinon.useFakeTimers() | |
@timer.start() | |
@clock.tick(5000) | |
@timer.stop() | |
afterEach -> | |
@clock.restore() | |
describe "wait 5 seconds", -> | |
beforeEach -> | |
@clock.tick(5000) | |
it "should return 5 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(5) | |
it "should return '0' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('0') | |
it "should return '05' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('05') | |
describe "re-start the timer with start()", -> | |
beforeEach -> | |
@timer.start() | |
describe "wait 5 seconds", -> | |
beforeEach -> | |
@clock.tick(5000) | |
it "should return 10 for getTotalSeconds()", -> | |
(expect @timer.getTotalSeconds()).toEqual(10) | |
it "should return '0' for getMinutes()", -> | |
(expect @timer.getMinutes()).toEqual('0') | |
it "should return '10' for getSeconds()", -> | |
(expect @timer.getSeconds()).toEqual('10') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment