summaryrefslogtreecommitdiff
path: root/rubywarrior/ultimate-beginner/spec/player_spec.rb
blob: 32ee857eec8ad14b130646b8d03ba458ae106b06 (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
require 'rspec'
require 'rspec-fakes'
require_relative '../player'

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

  context "when there is no obstacle" do
    let(:feeling) { fake }

    before :each do
      warrior.stub(:feel).and_return(feeling)
      feeling.stub(:empty?).and_return(true)
    end

    context "when your health is full" do
      before { warrior.stub(:health).and_return(20) }

      before { sut.play_turn(warrior) }

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

    context "when your health is low" do
      before { warrior.stub(:health).and_return(19) }

      before { sut.play_turn(warrior) }

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

  context "when there is sludge in front of you" do
    let(:feeling) { fake }

    before :each do
      warrior.stub(:feel).and_return(feeling)
      feeling.stub(:empty?).and_return(false)
    end

    context "when your health is full" do
      before :each do
        warrior.stub(:health).and_return(20)
      end

      before { sut.play_turn(warrior) }

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

    context "when your health is low" do
      before :each do
        warrior.stub(:health).and_return(19)
      end
      it "should walk backwards then rest" do
        sut.play_turn(warrior)
        warrior.should have_received(:walk!, :backward)
      end
    end
  end
end