diff options
| -rw-r--r-- | lib/north.rb | 6 | ||||
| -rw-r--r-- | spec/north_specs.rb | 20 | ||||
| -rw-r--r-- | spec/rover_specs.rb | 1 | ||||
| -rw-r--r-- | spec/ts_all.rb | 1 |
4 files changed, 26 insertions, 2 deletions
diff --git a/lib/north.rb b/lib/north.rb index 438d52d..9fe6aa8 100644 --- a/lib/north.rb +++ b/lib/north.rb @@ -5,7 +5,9 @@ class North def turn_left West.new end - def forward(current_location, terrain) - current_location[:y] = current_location[:y]+1 + def forward(location, terrain) + unless terrain.is_out_of_bounds({:x =>location[:x],:y => location[:y]+1}) + location[:y] = location[:y]+1 + end end end diff --git a/spec/north_specs.rb b/spec/north_specs.rb new file mode 100644 index 0000000..aeb1308 --- /dev/null +++ b/spec/north_specs.rb @@ -0,0 +1,20 @@ +require 'north' + +describe North do + before(:each) do + @sut = North.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[:y].must_equal 3 + end + before do + terrain = fake + terrain.stub(:is_out_of_bounds).with({:x => 0, :y => 4}).and_return(true) + @location = {:x => 0, :y => 3} + @sut.forward(@location, terrain) + end + end + end +end diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb index 5e99495..52b45c3 100644 --- a/spec/rover_specs.rb +++ b/spec/rover_specs.rb @@ -28,6 +28,7 @@ describe Rover do end describe "when driving forward" do before do + @terrain = fake @sut.move_forward(@terrain) end it "should increment the y coordinate on the terrain" do diff --git a/spec/ts_all.rb b/spec/ts_all.rb index 9bf43ab..b783a1e 100644 --- a/spec/ts_all.rb +++ b/spec/ts_all.rb @@ -7,4 +7,5 @@ require "book_specs" require "library_specs" require "stack_specs" require "rover_specs" +require "north_specs" require "specifications/find_all_books_by_author_specs" |
