vimtronner
Version:
A multi-player Vim trainer.
51 lines (37 loc) • 1.8 kB
text/coffeescript
ClientGameSocket = require '../../src/server/client_game_socket.coffee'
Game = require '../../src/models/game'
Cycle = require '../../src/models/cycle'
describe ClientGameSocket, ->
beforeEach ->
= {
on: sinon.stub(), join: sinon.stub(), emit: sinon.stub(), leave: sinon.stub()
}
= sinon.createStubInstance(Game)
.name = 'foo'
= sinon.createStubInstance(Cycle)
= new ClientGameSocket(, , )
describe 'construction', ->
context 'given a socket, game, and cycle', ->
it 'listens for movement events on the socket', ->
expect(.on).to.have.been.calledWith('movement', .onMovement)
it 'listens for disconnect events on the socket', ->
expect(.on).to.have.been.calledWith('disconnect', .onLeave)
it 'listens for leave events on the socket', ->
expect(.on).to.have.been.calledWith('leave', .onLeave)
it 'joins the socket to the game room', ->
expect(.join).to.have.been.calledWith(.name)
it 'emits the cycle down the socket', ->
expect(.emit).to.have.been.calledWith('cycle', )
describe 'onMovement', ->
context 'given a movement', ->
beforeEach ->
= 'm'
.onMovement
it 'controls the cycle', ->
expect(.navigate).to.have.been.calledWith()
describe 'onLeave', ->
beforeEach -> .onLeave()
it 'removes the cycle from the game', ->
expect(.removeCycle).to.have.been.calledWith()
it 'exits the socket from the game room', ->
expect(.leave).to.have.been.calledWith(.name)