Daniel@0: describe("Player", function() { Daniel@0: var player; Daniel@0: var song; Daniel@0: Daniel@0: beforeEach(function() { Daniel@0: player = new Player(); Daniel@0: song = new Song(); Daniel@0: }); Daniel@0: Daniel@0: it("should be able to play a Song", function() { Daniel@0: player.play(song); Daniel@0: expect(player.currentlyPlayingSong).toEqual(song); Daniel@0: Daniel@0: //demonstrates use of custom matcher Daniel@0: expect(player).toBePlaying(song); Daniel@0: }); Daniel@0: Daniel@0: describe("when song has been paused", function() { Daniel@0: beforeEach(function() { Daniel@0: player.play(song); Daniel@0: player.pause(); Daniel@0: }); Daniel@0: Daniel@0: it("should indicate that the song is currently paused", function() { Daniel@0: expect(player.isPlaying).toBeFalsy(); Daniel@0: Daniel@0: // demonstrates use of 'not' with a custom matcher Daniel@0: expect(player).not.toBePlaying(song); Daniel@0: }); Daniel@0: Daniel@0: it("should be possible to resume", function() { Daniel@0: player.resume(); Daniel@0: expect(player.isPlaying).toBeTruthy(); Daniel@0: expect(player.currentlyPlayingSong).toEqual(song); Daniel@0: }); Daniel@0: }); Daniel@0: Daniel@0: // demonstrates use of spies to intercept and test method calls Daniel@0: it("tells the current song if the user has made it a favorite", function() { Daniel@0: spyOn(song, 'persistFavoriteStatus'); Daniel@0: Daniel@0: player.play(song); Daniel@0: player.makeFavorite(); Daniel@0: Daniel@0: expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true); Daniel@0: }); Daniel@0: Daniel@0: //demonstrates use of expected exceptions Daniel@0: describe("#resume", function() { Daniel@0: it("should throw an exception if song is already playing", function() { Daniel@0: player.play(song); Daniel@0: Daniel@0: expect(function() { Daniel@0: player.resume(); Daniel@0: }).toThrowError("song is already playing"); Daniel@0: }); Daniel@0: }); Daniel@0: });