require 'spec_helper'

RSpec.describe :Models do
  context 'Game' do
    it 'should create a new game with no players or kills' do
      game = Game.new
      expect(game.number_of_kills).to eq(0)
      expect(game.players.length).to eq(0)
    end
  end

  context 'Kill' do
    before(:each) do
      @game = Game.new
      @killer_name = '#Killer'
      @killed_name = '#Killed'
      @cause = '#Cause'
    end

    it 'should assign kill' do
      @game.assign_kill(@killer_name, @killed_name, @cause)
      expect(@game.number_of_kills).to eq(1)
      expect(@game.players.length ).to eq(2)

      kill = @game.kills[0]
      expect(kill.killer.kills ).to eq(1)
      expect(kill.killed.deaths).to eq(1)
    end

    it 'should not duplicate players' do
      @game.assign_kill(@killer_name, @killed_name, @cause)
      @game.assign_kill(@killer_name, @killed_name, @cause)

      expect(@game.number_of_kills).to eq(2)
      expect(@game.players.length).to eq(2)
    end

    it 'should assign <world> kill, but not create kill entry' do
      @game.assign_kill(@killer_name, @killed_name, @cause)
      @game.assign_kill('<world>', @killed_name, @cause)

      expect(@game.number_of_kills).to eq(2)
      expect(@game.players.length).to eq(2)
    end

    it 'should discount a kill when killed by <world>' do
      @game.assign_kill(@killer_name, @killed_name, @cause)
      @game.assign_kill(@killer_name, @killed_name, @cause)
      @game.assign_kill('<world>', @killer_name, @cause)
      @game.assign_kill('<world>', @killed_name, @cause)

      expect(@game.number_of_kills).to eq(4)
      expect(@game.players[@killer_name].kills).to eq(1)
      expect(@game.players[@killed_name].kills).to eq(0)
    end
  end
end
