The Reference Universe widget now specifies to use the correct target.
[mkws-moved-to-github.git] / examples / jasmine / spec / PlayerSpec.js
1 describe("Player", function() {
2   var player;
3   var song;
4
5   beforeEach(function() {
6     player = new Player();
7     song = new Song();
8   });
9
10   it("should be able to play a Song", function() {
11     player.play(song);
12     expect(player.currentlyPlayingSong).toEqual(song);
13
14     //demonstrates use of custom matcher
15     expect(player).toBePlaying(song);
16   });
17
18   describe("when song has been paused", function() {
19     beforeEach(function() {
20       player.play(song);
21       player.pause();
22     });
23
24     it("should indicate that the song is currently paused", function() {
25       expect(player.isPlaying).toBeFalsy();
26
27       // demonstrates use of 'not' with a custom matcher
28       expect(player).not.toBePlaying(song);
29     });
30
31     it("should be possible to resume", function() {
32       player.resume();
33       expect(player.isPlaying).toBeTruthy();
34       expect(player.currentlyPlayingSong).toEqual(song);
35     });
36   });
37
38   // demonstrates use of spies to intercept and test method calls
39   it("tells the current song if the user has made it a favorite", function() {
40     spyOn(song, 'persistFavoriteStatus');
41
42     player.play(song);
43     player.makeFavorite();
44
45     expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
46   });
47
48   //demonstrates use of expected exceptions
49   describe("#resume", function() {
50     it("should throw an exception if song is already playing", function() {
51       player.play(song);
52
53       expect(function() {
54         player.resume();
55       }).toThrow("song is already playing");
56     });
57   });
58 });