 
       runs ->
         expect(hostParticipantExitedHandler).toHaveBeenCalledWith(login: 'octocat', clientId: guestSession.clientId)
-        expect(hostSession.getParticipants()).toEqual [login: 'hubot', clientId: hostSession.clientId]
-        expect(hostSession.getOtherParticipants()).toEqual []
+        expect(leaderSession.getParticipants()).toEqual [login: 'hubot', clientId: leaderSession.clientId]
+        expect(leaderSession.getOtherParticipants()).toEqual []


      runs ->
        expect(guestStartedHandler).toHaveBeenCalledWith [
          { login: 'hubot', clientId: hostSession.clientId }
          { login: 'octocat', clientId: guestSession.clientId }
        ]
        expect(guestSession.getParticipants()).toEqual [
          { login: 'hubot', clientId: hostSession.clientId }
          { login: 'octocat', clientId: guestSession.clientId }
        ]
        expect(guestSession.getOtherParticipants()).toEqual [
          { login: 'hubot', clientId: hostSession.clientId }
        ]

      waitsFor "host to see guest enter", -> hostParticipantEnteredHandler.callCount > 0

      runs ->
        expect(hostParticipantEnteredHandler).toHaveBeenCalledWith(login: 'octocat', clientId: guestSession.clientId)
        expect(hostSession.getParticipants()).toEqual [
          { login: 'hubot', clientId: hostSession.clientId }
          { login: 'octocat', clientId: guestSession.clientId }
        ]
        expect(hostSession.getOtherParticipants()).toEqual [
          { login: 'octocat', clientId: guestSession.clientId }
        ]
        guestSession.stop()


describe "Collaboration", ->
  describe "when a host and a guest join a channel", ->
    [server, leaderSession, guestSession, leaderStartedHandler, guestStartedHandler, guestStoppedHandler, token, userDataByToken] = []

    beforeEach ->
      jasmine.unspy(window, 'setTimeout')
