Commit 7aba0b9

mo k <mo@mokhan.ca>
2012-08-10 03:00:10
implement north heading.
1 parent a3608bf
Changed files (2)
lib/north.rb
@@ -1,3 +1,11 @@
 class North
-
+  def turn_right
+    East.new
+  end
+  def turn_left
+    West.new
+  end
+  def forward(location)
+    location[:y] = location[:y]+1
+  end
 end
spec/north_spec.rb
@@ -0,0 +1,24 @@
+require "spec_helper"
+
+describe North do
+  let(:sut) { North.new }
+  context "when moving forward" do
+    it "should move to the next position" do
+      @location[:y].should == 4
+    end
+    before do
+      @location = {:x => 0, :y => 3}
+      sut.forward(@location)
+    end
+  end
+  context "when turning right" do
+    it "should face east" do
+      sut.turn_right.should be_an_instance_of(East)
+    end
+  end
+  context "when turning left" do
+    it "should face west" do
+      sut.turn_left.should be_an_instance_of(West)
+    end
+  end
+end