Commit 053a7ad
Changed files (2)
lib
spec
unit
lib/rover.rb
@@ -1,6 +1,6 @@
class Rover
attr_reader :location
- def initialize(heading, coordinates, plateau = nil)
+ def initialize(heading, coordinates, plateau)
@heading = heading
@location = coordinates
@plateau = plateau
@@ -17,9 +17,6 @@ class Rover
def forward
@plateau.move_forward(@heading, @location)
end
- def move_forward(plateau)
- plateau.move_forward(@heading, @location)
- end
def to_s
"#{@location[:x]} #{@location[:y]} #{@heading}"
end
spec/unit/rover_spec.rb
@@ -3,8 +3,9 @@ require 'spec_helper'
describe Rover do
def create_sut(heading, x = 0, y = 0)
directions = {:north => North.new, :east => East.new, :west => West.new, :south => South.new}
- Rover.new(directions[heading],{ :x =>x,:y => y })
+ Rover.new(directions[heading],{ :x => x,:y => y }, plateau)
end
+ let(:plateau) { fake }
context "when facing north" do
let(:sut) { create_sut :north, 0, 0 }
@@ -74,14 +75,14 @@ describe Rover do
context "when driving forward" do
it "should move forward along the terrain" do
- @terrain.should have_received(:move_forward, @sut.instance_variable_get(:@heading), @sut.location )
+ plateau.should have_received(:move_forward, @sut.instance_variable_get(:@heading), @sut.location )
end
before do
- @terrain = fake
@sut = create_sut(:north)
- @sut.move_forward(@terrain)
+ @sut.forward
end
end
+
context "when printed" do
it "should return the heading and location" do
create_sut(:north).to_s.should == '0 0 N'