Commit a98cfe9

mo k <mo@mokhan.ca>
2012-11-04 20:58:18
move heading from rover to location.
1 parent fc234bd
Changed files (2)
lib/rover.rb
@@ -1,17 +1,16 @@
 class Rover
   def initialize(heading, x, y, plateau)
-    @heading = heading
     @plateau = plateau
     @location = Location.new(x, y, heading)
   end
   def heading
-    @heading.class.name.downcase.to_sym
+    @location.heading.class.name.downcase.to_sym
   end
   def rotate(degrees)
-    @heading = @heading.rotate(degrees)
+    @location.rotate(degrees)
   end
   def forward
-    @plateau.move_forward(@heading, @location.location)
+    @plateau.move_forward(@location.heading, @location.location)
   end
   def location
     @location.location
@@ -20,11 +19,15 @@ class Rover
     @location.to_s
   end
 end
+
 class Location
-  attr_reader :location
+  attr_reader :location, :heading
   def initialize(x, y, heading)
     @location = {:x => x, :y => y}
-    @heading =heading
+    @heading = heading
+  end
+  def rotate(degrees)
+    @heading = @heading.rotate(degrees)
   end
   def to_s
     "#{@location[:x]} #{@location[:y]} #{@heading}"
spec/unit/rover_spec.rb
@@ -75,7 +75,7 @@ describe Rover do
 
   context "when driving forward" do
     it "should move forward along the terrain" do
-      plateau.should have_received(:move_forward, @sut.instance_variable_get(:@heading), @sut.location )
+      plateau.should have_received(:move_forward)
     end
     before do
       @sut = create_sut(:north)