summaryrefslogtreecommitdiff
path: root/rubywarrior/alimo-beginner/spec/player_spec.rb
blob: 7dff3d83a315bc7f8901aeef65d354f4a9d5d3fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'rspec-fakes'
require 'ostruct'
require_relative '../player.rb'

describe Player do
  let(:player) { Player.new }
  let(:warrior) { fake }

  context "when there is no obstacle in the way" do
    let(:space) { OpenStruct.new(:empty? => true) }
    before { warrior.stub(:health).and_return(20) }

    it "should walk forward" do
      warrior.stub(:feel).and_return(space)
      player.play_turn(warrior)
      warrior.should have_received(:walk!)
    end
  end

  context "when there is an obstacle in the way" do
    let(:space) { OpenStruct.new(:empty? => false) }

    before :each do
      warrior.stub(:feel).and_return(space)
    end

    context "when the player has more than 50% of it's original health" do
      let(:starting_health) { 20 }

      before :each do
        warrior.stub(:health).and_return(starting_health)
        player.play_turn(warrior)
      end

      it "should attack obstacle" do
        warrior.should have_received(:attack!)
      end

      it "should not rest" do
        warrior.should_not have_received(:rest!)
      end
    end

    context "when our health reaches 50%" do
      let(:starting_health) { 20 }
      let(:new_warrior) { fake }

      before :each do
        warrior.stub(:health).and_return(starting_health)
        player.play_turn(warrior)

        new_warrior.stub(:health).and_return(starting_health * 0.5)
        new_warrior.stub(:feel).and_return(space)
        player.play_turn(new_warrior)
      end

      it "should step back and rest" do
        new_warrior.should have_received(:rest!)
      end

      it "should not attack" do
        new_warrior.should_not have_received(:attack!)
      end
    end
  end
  context "when health is low" do
    it "should stay resting" do
      
    end
  end
end