diff options
| author | mo k <mo@mokhan.ca> | 2012-02-11 15:08:41 -0700 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-02-11 15:08:41 -0700 |
| commit | d21d6b13d211e57db037acdd09dbd82b371af9ab (patch) | |
| tree | 0202ca4512540b9bba9c49875dacf7912c107714 | |
| parent | b1c2f983456637975dc41dee6f5bab65d2afaa66 (diff) | |
when facing west and turning left and right.
| -rw-r--r-- | lib/rover.rb | 4 | ||||
| -rw-r--r-- | spec/rover_specs.rb | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/rover.rb b/lib/rover.rb index 591ec5a..ad4042d 100644 --- a/lib/rover.rb +++ b/lib/rover.rb @@ -11,6 +11,8 @@ class Rover @heading = :south elsif @heading == :south @heading = :west + elsif @heading == :west + @heading = :north end end def turn_left @@ -20,6 +22,8 @@ class Rover @heading = :north elsif @heading == :south @heading = :east + elsif @heading == :west + @heading = :south end end end diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb index 7bef598..318590f 100644 --- a/spec/rover_specs.rb +++ b/spec/rover_specs.rb @@ -59,4 +59,22 @@ describe Rover do end end + describe "when facing west" do + before do + @sut.heading= :west + end + describe "when turning right" do + it "should face north" do + @sut.turn_right + @sut.heading.must_equal :north + end + end + describe "when turning left" do + it "should face south" do + @sut.turn_left + @sut.heading.must_equal :south + end + end + end + end |
