From 2d498cb88bff144327510932da9770fe231bafd6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 16 May 2014 16:13:25 +0200 Subject: [PATCH] adapt JSON parsing in tests to allow for omitted fields --- features/support/route.rb | 68 +++++++++++++++++---------------- features/testbot/status.feature | 4 +- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/features/support/route.rb b/features/support/route.rb index f32c61600..2f930751e 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -93,10 +93,12 @@ def route_status response end def extract_instruction_list instructions, index, postfix=nil - instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }. - map { |r| r[index] }. - map { |r| (r=="" || r==nil) ? '""' : "#{r}#{postfix}" }. - join(',') + if instructions + instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }. + map { |r| r[index] }. + map { |r| (r=="" || r==nil) ? '""' : "#{r}#{postfix}" }. + join(',') + end end def way_list instructions @@ -112,33 +114,35 @@ def bearing_list instructions end def turn_list instructions - types = { - 0 => :none, - 1 => :straight, - 2 => :slight_right, - 3 => :right, - 4 => :sharp_right, - 5 => :u_turn, - 6 => :sharp_left, - 7 => :left, - 8 => :slight_left, - 9 => :via, - 10 => :head, - 11 => :enter_roundabout, - 12 => :leave_roundabout, - 13 => :stay_roundabout, - 14 => :start_end_of_street, - 15 => :destination, - 16 => :enter_contraflow, - 17 => :leave_contraflow - } - # replace instructions codes with strings - # "11-3" (enter roundabout and leave a 3rd exit) gets converted to "enter_roundabout-3" - instructions.map do |r| - r[0].to_s.gsub(/^\d*/) do |match| - types[match.to_i].to_s - end - end.join(',') + if instructions + types = { + 0 => :none, + 1 => :straight, + 2 => :slight_right, + 3 => :right, + 4 => :sharp_right, + 5 => :u_turn, + 6 => :sharp_left, + 7 => :left, + 8 => :slight_left, + 9 => :via, + 10 => :head, + 11 => :enter_roundabout, + 12 => :leave_roundabout, + 13 => :stay_roundabout, + 14 => :start_end_of_street, + 15 => :destination, + 16 => :enter_contraflow, + 17 => :leave_contraflow + } + # replace instructions codes with strings + # "11-3" (enter roundabout and leave a 3rd exit) gets converted to "enter_roundabout-3" + instructions.map do |r| + r[0].to_s.gsub(/^\d*/) do |match| + types[match.to_i].to_s + end + end.join(',') + end end def mode_list instructions @@ -151,4 +155,4 @@ end def distance_list instructions extract_instruction_list instructions, 2, "m" -end \ No newline at end of file +end diff --git a/features/testbot/status.feature b/features/testbot/status.feature index 061b614a3..4fa15ebb3 100644 --- a/features/testbot/status.feature +++ b/features/testbot/status.feature @@ -27,7 +27,7 @@ Feature: Status messages | nodes | | ab | | cd | - + When I route I should get | from | to | route | status | message | | a | b | ab | 0 | Found route between points | @@ -64,4 +64,4 @@ Feature: Status messages | viaroute/loc=1,1&loc=1,1 | 400 | Query string malformed close to position 9 | | viaroute/loc=1,1&loc=1,1,1 | 400 | Query string malformed close to position 9 | | viaroute/loc=1,1&loc=x | 400 | Query string malformed close to position 9 | - | viaroute/loc=1,1&loc=x,y | 400 | Query string malformed close to position 9 | \ No newline at end of file + | viaroute/loc=1,1&loc=x,y | 400 | Query string malformed close to position 9 |