 
 		beforeEach ->
 			@ProjectInvite::save = sinon.spy (cb) -> cb(null, this)
+			@randomBytesSpy = sinon.spy(@Crypto, 'randomBytes')
 			@CollaboratorsEmailHandler.notifyUserOfProjectInvite = sinon.stub()
 			@call = (callback) =>
 				@CollaboratorsInviteHandler.inviteToProject @projectId, @sendingUserId, @email, @privileges, callback
+
+		afterEach ->
+			@randomBytesSpy.restore()
 
 		describe 'when all goes well', ->
 

			'../Contacts/ContactManager': @ContactManager = {}
			'../../models/Project': {Project: @Project}
			'../../models/ProjectInvite': {ProjectInvite: @ProjectInvite}

		@projectId = ObjectId()
		@sendingUserId = ObjectId()

					expect(invite).to.have.all.keys ['_id', 'email', 'token', 'sendingUserId', 'projectId', 'privileges']
					done()

			it 'should have generated a random token', (done) ->
				@call (err, invite) =>
					@randomBytesSpy.callCount.should.equal 1
					done()

			it 'should have called ProjectInvite.save', (done) ->
				@call (err, invite) =>
					@ProjectInvite::save.callCount.should.equal 1
