summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]lib/east.rb6
-rwxr-xr-xspec/east_specs.rb20
-rwxr-xr-xspec/rover_specs.rb1
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/east.rb b/lib/east.rb
index 1699ffc..fd5752d 100644..100755
--- a/lib/east.rb
+++ b/lib/east.rb
@@ -5,7 +5,9 @@ class East
def turn_left
North.new
end
- def forward(current_location, terrain)
- current_location[:x] = current_location[:x]+1
+ def forward(location, terrain)
+ unless terrain.is_out_of_bounds( {:x => location[:x]+1, :y => location[:y]})
+ location[:x] = location[:x]+1
+ end
end
end
diff --git a/spec/east_specs.rb b/spec/east_specs.rb
new file mode 100755
index 0000000..5060956
--- /dev/null
+++ b/spec/east_specs.rb
@@ -0,0 +1,20 @@
+require 'east'
+
+describe East do
+ before(:each) do
+ @sut = East.new
+ end
+ describe "when at the edge of the terrain" do
+ describe "when moving forward" do
+ it "should just stay at the current position" do
+ @location[:x].must_equal 0
+ end
+ before do
+ terrain = fake
+ terrain.stub(:is_out_of_bounds).with({:x => -1, :y => 0}).and_return(true)
+ @location = {:x => 0, :y => 0}
+ @sut.forward(@location, terrain)
+ end
+ end
+ end
+end
diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb
index f8d15f8..8c3da03 100755
--- a/spec/rover_specs.rb
+++ b/spec/rover_specs.rb
@@ -82,6 +82,7 @@ describe Rover do
end
describe "when driving forward" do
before do
+ @terrain = fake
@sut.move_forward(@terrain)
end
it "should increment the x coordinate on the terrain" do