Commit a3608bf
Changed files (6)
lib/east.rb
@@ -0,0 +1,11 @@
+class East
+ def turn_right
+ South.new
+ end
+ def turn_left
+ North.new
+ end
+ def forward(location)
+ location[:x] = location[:x]+1
+ end
+end
lib/north.rb
@@ -0,0 +1,3 @@
+class North
+
+end
lib/south.rb
@@ -0,0 +1,3 @@
+class South
+
+end
lib/west.rb
@@ -0,0 +1,3 @@
+class West
+
+end
spec/east_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe East do
+ let(:sut){ East.new }
+
+ context "when moving forward" do
+ it "should move to the next position" do
+ @location[:x].should == 1
+ end
+ before do
+ @location = {:x => 0, :y => 0}
+ sut.forward(@location)
+ end
+ end
+ context "when turning right" do
+ it "should face South" do
+ sut.turn_right.should be_an_instance_of(South)
+ end
+ end
+end
spec/spec_helper.rb
@@ -2,3 +2,7 @@ require "rspec"
require "rspec-fakes"
require_relative '../lib/terrain'
+require_relative '../lib/north'
+require_relative '../lib/east'
+require_relative '../lib/south'
+require_relative '../lib/west'