Skip to content

Commit

Permalink
adding examples of native spies vs Sinon spies and adding another cav…
Browse files Browse the repository at this point in the history
…eat to the readme

	addresses #7
  • Loading branch information
Sam Breed committed Oct 30, 2011
1 parent fc79703 commit 01f6f02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -69,7 +69,10 @@ In addition to the test runners, [Sinon.js][sinon] is included by
default. It's a great set of tooling for mocking, spies, and XHR
faking. In general, Sinon.js will not affect any pre-existing test
suites, but there are some gotcha's. Be sure to [check the out the
documentation][sinon-docs] if you haven't used it before
documentation][sinon-docs] if you haven't used it before.

Sinon overwrites Jasmine's spyOn implementation, so be sure to not
include it if you plan on using that part of Jasmine.

In Sinon's default settings, _setTimeout and setInterval are
overwritten_. To change this behavior you need to modify Sinon's config
Expand Down
20 changes: 11 additions & 9 deletions test/dummy/spec/javascripts/jasmine_examples/player_spec.js.coffee
Expand Up @@ -28,15 +28,6 @@ describe 'Player' , ->
expect( @player.isPlaying ).toBeTruthy()
expect( @player.currentlyPlayingSong ).toEqual @song

# demonstrates use of spies to intercept and test method calls
xit 'tells the current song if the user has made it a favorite' , ->
spy = sinon.spy @song, 'persistFavoriteStatus'

@player.play @song
@player.makeFavorite()

expect( spy ).toHaveBeenCalled()

# demonstrates use of expected exceptions
describe '#resume' , ->
it 'should throw an exception if song is already playing' , ->
Expand All @@ -46,3 +37,14 @@ describe 'Player' , ->
@player.resume()
.toThrow 'song is already playing'

it 'should use native spies', ->
foo = { bar: ( -> ) }
spyOn( foo, 'bar' )
foo.bar()
expect( foo.bar ).toHaveBeenCalled()

it 'should use Sinon spies', ->
foo = { bar: ( -> ) }
spy = sinon.spy( foo, 'bar' )
foo.bar()
expect( spy ).toHaveBeenCalled()

0 comments on commit 01f6f02

Please sign in to comment.