diff --git a/Gemfile b/Gemfile index b0db7beada..114808e497 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,5 @@ source "http://rubygems.org" gem "cucumber" gem "rake" gem "osmlib-base" -gem "sys-proctable" \ No newline at end of file +gem "sys-proctable" +gem "rspec-expectations" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index d4bff7b413..32a3fdada1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,8 @@ GEM json (1.6.5) osmlib-base (0.1.4) rake (0.9.2.2) + rspec-expectations (2.11.3) + diff-lcs (~> 1.1.3) sys-proctable (0.9.1) term-ansicolor (1.0.7) @@ -24,4 +26,5 @@ DEPENDENCIES cucumber osmlib-base rake + rspec-expectations sys-proctable diff --git a/features/bad.feature b/features/bad.feature index 11c767484b..af1f46c652 100644 --- a/features/bad.feature +++ b/features/bad.feature @@ -3,14 +3,25 @@ Feature: Handle bad data in a graceful manner Scenario: Empty dataset Given the node map - | a | b | + | | Given the ways | nodes | - When I route I should get - | from | to | route | - | a | b | | + When I preprocess data + Then preparing should return code 255 + + Scenario: Only dead-end oneways + Given the node map + | a | b | c | + + Given the ways + | nodes | oneway | + | ab | yes | + | cb | yes | + + When I preprocess data + Then preparing should return code 255 Scenario: Start/end point at the same location Given the node map @@ -29,7 +40,7 @@ Feature: Handle bad data in a graceful manner | 2 | 2 | | @poles - Scenario: No routing close to the north/south pole + Scenario: Routing close to the north/south pole Mercator is undefined close to the poles. All nodes and request with latitude to close to either of the poles should therefore be ignored. diff --git a/features/step_definitions/errors.rb b/features/step_definitions/errors.rb new file mode 100644 index 0000000000..554e078576 --- /dev/null +++ b/features/step_definitions/errors.rb @@ -0,0 +1,15 @@ + +When /^I preprocess data$/ do + begin + osrm_kill + reprocess + rescue OSRMError => e + @process_error = e + end +end + +Then /^preparing should return code (\d+)$/ do |code| + @process_error.class.should == OSRMError + @process_error.process.should == 'osrm-prepare' + @process_error.code.to_i.should == code.to_i +end diff --git a/features/support/data.rb b/features/support/data.rb index 11ea59022e..320cd45000 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -176,7 +176,7 @@ def reprocess log "== Extracting #{@osm_file}.osm...", :preprocess unless system "../osrm-extract #{@osm_file}.osm.pbf 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" log "*** Exited with code #{$?.exitstatus}.", :preprocess - raise "*** osrm-extract exited with code #{$?.exitstatus}. The file preprocess.log might contain more info." + raise OSRMError.new 'osrm-extract', $?.exitstatus, "*** osrm-extract exited with code #{$?.exitstatus}. The file preprocess.log might contain more info." end log '', :preprocess end @@ -185,7 +185,7 @@ def reprocess log "== Preparing #{@osm_file}.osm...", :preprocess unless system "../osrm-prepare #{@osm_file}.osrm #{@osm_file}.osrm.restrictions 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" log "*** Exited with code #{$?.exitstatus}.", :preprocess - raise "*** osrm-prepare exited with code #{$?.exitstatus}. The file preprocess.log might contain more info." + raise OSRMError.new 'osrm-prepare', $?.exitstatus, "*** osrm-prepare exited with code #{$?.exitstatus}. The file preprocess.log might contain more info." end log '', :preprocess end @@ -193,4 +193,3 @@ def reprocess write_server_ini end end - diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000000..9fb7ec8d1c --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1 @@ +require 'rspec/expectations' \ No newline at end of file diff --git a/features/support/exceptions.rb b/features/support/exceptions.rb new file mode 100644 index 0000000000..75cda9ba77 --- /dev/null +++ b/features/support/exceptions.rb @@ -0,0 +1,10 @@ + +class OSRMError < StandardError + attr_accessor :process, :code, :msg + + def initialize process, code, msg + @process = process + @code = code + @msg = msg + end +end \ No newline at end of file