main
 1require 'spec_helper'
 2
 3describe Rover do
 4  def create_sut(heading, x = 0, y = 0)
 5    directions = {:north => North.new, :east => East.new, :west => West.new, :south => South.new}
 6    Rover.new(directions[heading], x, y , plateau)
 7  end
 8  let(:plateau) { fake }
 9
10  context "when facing north" do
11    let(:sut) { create_sut :north, 0, 0 }
12    context "when turning right" do
13      it "should face east" do
14        sut.rotate(90)
15        sut.is_facing(:east).should be_true
16      end
17    end
18    context "when turning left" do
19      it "should face west" do
20        sut.rotate(-90)
21        sut.is_facing(:west).should be_true
22      end
23    end
24  end
25
26  context "when facing south" do
27    let(:sut) { create_sut :south, 0, 3 }
28    context "when turning right" do
29      it "should face west" do
30        sut.rotate(90)
31        sut.is_facing(:west).should be_true
32      end
33    end
34    context "when turning left" do
35      it "should face east" do
36        sut.rotate(-90)
37        sut.is_facing(:east).should be_true
38      end
39    end
40  end
41
42  context "when facing east" do
43    let(:sut) { create_sut :east }
44
45    context "when turning right" do
46      it "should face south" do
47        sut.rotate(90)
48        sut.is_facing(:south).should be_true
49      end
50    end
51    context "when turning left" do
52      it "should face north" do
53        sut.rotate(-90)
54        sut.is_facing(:north).should be_true
55      end
56    end
57  end
58
59  context "when facing west" do
60    let(:sut){ create_sut :west, 1, 0 }
61
62    context "when turning right" do
63      it "should face north" do
64        sut.rotate(90)
65        sut.is_facing(:north).should be_true
66      end
67    end
68    context "when turning left" do
69      it "should face south" do
70        sut.rotate(-90)
71        sut.is_facing(:south).should be_true
72      end
73    end
74  end
75
76  context "when printed" do
77    it "should return the heading and location" do
78      create_sut(:north).to_s.should == '0 0 N'
79    end
80  end
81end