make cuke tests work with ruby 2.x

This commit is contained in:
Emil Tin 2013-08-02 09:34:58 +02:00
parent ec7d3a9885
commit 63059cfab3
3 changed files with 17 additions and 12 deletions

View File

@ -4,7 +4,7 @@ DEFAULT_PORT = 5000
puts "Ruby version #{RUBY_VERSION}" puts "Ruby version #{RUBY_VERSION}"
unless RUBY_VERSION =~ /^1.9/ unless RUBY_VERSION.to_f >= 1.9
raise "*** Please upgrade to Ruby 1.9.x to run the OSRM cucumber tests" raise "*** Please upgrade to Ruby 1.9.x to run the OSRM cucumber tests"
end end

View File

@ -1,5 +1,8 @@
require 'digest/sha1' require 'digest/sha1'
bin_extract_hash = nil
profile_hashes = nil
def hash_of_files paths def hash_of_files paths
paths = [paths] unless paths.is_a? Array paths = [paths] unless paths.is_a? Array
hash = Digest::SHA1.new hash = Digest::SHA1.new
@ -16,8 +19,8 @@ end
def profile_hash def profile_hash
@@profile_hashes ||= {} profile_hashes ||= {}
@@profile_hashes[@profile] ||= hash_of_files "#{PROFILES_PATH}/#{@profile}.lua" profile_hashes[@profile] ||= hash_of_files "#{PROFILES_PATH}/#{@profile}.lua"
end end
def osm_hash def osm_hash
@ -29,15 +32,15 @@ def lua_lib_hash
end end
def bin_extract_hash def bin_extract_hash
@@bin_extract_hash ||= hash_of_files "#{BIN_PATH}/osrm-extract" bin_extract_hash ||= hash_of_files "#{BIN_PATH}/osrm-extract"
end end
def bin_prepare_hash def bin_prepare_hash
@@bin_prepare_hash ||= hash_of_files "#{BIN_PATH}/osrm-prepare" bin_prepare_hash ||= hash_of_files "#{BIN_PATH}/osrm-prepare"
end end
def bin_routed_hash def bin_routed_hash
@@bin_routed_hash ||= hash_of_files "#{BIN_PATH}/osrm-routed" bin_routed_hash ||= hash_of_files "#{BIN_PATH}/osrm-routed"
end end
#combine state of data, profile and binaries into a hash that identifies the exact test scenario #combine state of data, profile and binaries into a hash that identifies the exact test scenario

View File

@ -1,23 +1,25 @@
require 'OSM/StreamParser' require 'OSM/StreamParser'
locations = nil
class OSMTestParserCallbacks < OSM::Callbacks class OSMTestParserCallbacks < OSM::Callbacks
@@locations = nil locations = nil
def self.locations def self.locations
if @@locations if locations
@@locations locations
else else
#parse the test file, so we can later reference nodes and ways by name in tests #parse the test file, so we can later reference nodes and ways by name in tests
@@locations = {} locations = {}
file = 'test/data/test.osm' file = 'test/data/test.osm'
callbacks = OSMTestParserCallbacks.new callbacks = OSMTestParserCallbacks.new
parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks) parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks)
parser.parse parser.parse
puts @@locations puts locations
end end
end end
def node(node) def node(node)
@@locations[node.name] = [node.lat,node.lon] locations[node.name] = [node.lat,node.lon]
end end
end end