Commit 0686757
Changed files (3)
lib
spec
lib/west.rb
@@ -1,3 +1,11 @@
class West
-
+ def turn_right
+ North.new
+ end
+ def turn_left
+ South.new
+ end
+ def forward(current_location)
+ current_location[:x] = current_location[:x]-1
+ end
end
spec/east_spec.rb
@@ -17,4 +17,9 @@ describe East do
sut.turn_right.should be_an_instance_of(South)
end
end
+ context "when turning left" do
+ it "should face North" do
+ sut.turn_left.should be_an_instance_of(North)
+ end
+ end
end
spec/west_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe West do
+ let(:sut){ West.new }
+
+ context "when moving forward" do
+ it "should move to the next position" do
+ @location[:x].should == 0
+ end
+ before do
+ @location = {:x => 1, :y => 0}
+ sut.forward(@location)
+ end
+ end
+ context "when turning right" do
+ it "should face North" do
+ sut.turn_right.should be_an_instance_of(North)
+ end
+ end
+ context "when turning left" do
+ it "should face South" do
+ sut.turn_left.should be_an_instance_of(South)
+ end
+ end
+end