 
 
 
-  describe "MATCHING (players with instances of games)", () ->
+  describe "MATCHING (players with games)", () ->
+
+    InBetween = Date.now()
 
     it "should allow any logged in player to host games", (done) ->
       @anyplayer.emit 'host', { game: "my.game", min: 2, max: 3}

      @lukas.send "happy again :-)"
      @anyplayer.on 'message', (msg) ->
        expect(msg).to.equal "Lukas:   happy again :-)"
      @anotherplayer.on 'message', (msg) ->
        expect(msg).to.equal "Lukas:   happy again :-)"
        done()

      @anyplayer.on 'join', (msg) =>
        expect(msg.player).to.equal "Ananda"
        expect(msg.id).to.equal MatchId
        History += 1
        done()

  
  


  describe "CUSTOM MESSAGING", () ->

    it "should broadcast game messages among players of a match", (done) ->
      @anotherplayer.emit 'move', { foo: "my", data: 42 }
      @anyplayer.on 'move', (msg) =>
        expect(msg).to.deep.equal( { foo: "my", data: 42 }
        History += 1
        done()





  describe "HISTORY (catch up)", ->

    replay = History
    
    it "should tell no diff if nothing happened", (done) ->
      @anyplayer.emit 'history', { since: Date.now }
      setTimeout ( () ->
        expect(History).to.equal replay # still the same
        ), 333 #ms

    it "should tell the difference if something happened in between", (done) ->
      History = 0
      @anyplayer.emit 'history', { since: InBetween }
      setTimeout ( () ->
        expect(History).to.equal 3   # [host, join, move] have been replayed 
        ), 55 #ms

    it "should tell the difference of everything that ever happened", (done) ->
      History = 0
      @anyplayer.emit 'history', { since: BeginOfTest }
      setTimeout ( () ->
        expect(History).to.equal replay
        ), 55 #ms

 



