From 63059cfab35191bd4e425a8721062c310cf1e687 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Fri, 2 Aug 2013 09:34:58 +0200 Subject: [PATCH] make cuke tests work with ruby 2.x --- features/support/env.rb | 2 +- features/support/hash.rb | 13 ++++++++----- features/support/osm_parser.rb | 14 ++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 13a0b0c5e..a6a99b9f5 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -4,7 +4,7 @@ DEFAULT_PORT = 5000 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" end diff --git a/features/support/hash.rb b/features/support/hash.rb index e37a6f2df..7639364fb 100644 --- a/features/support/hash.rb +++ b/features/support/hash.rb @@ -1,5 +1,8 @@ require 'digest/sha1' +bin_extract_hash = nil +profile_hashes = nil + def hash_of_files paths paths = [paths] unless paths.is_a? Array hash = Digest::SHA1.new @@ -16,8 +19,8 @@ end def profile_hash - @@profile_hashes ||= {} - @@profile_hashes[@profile] ||= hash_of_files "#{PROFILES_PATH}/#{@profile}.lua" + profile_hashes ||= {} + profile_hashes[@profile] ||= hash_of_files "#{PROFILES_PATH}/#{@profile}.lua" end def osm_hash @@ -29,15 +32,15 @@ def lua_lib_hash end 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 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 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 #combine state of data, profile and binaries into a hash that identifies the exact test scenario diff --git a/features/support/osm_parser.rb b/features/support/osm_parser.rb index ea4e9bd16..3331a70bc 100644 --- a/features/support/osm_parser.rb +++ b/features/support/osm_parser.rb @@ -1,23 +1,25 @@ require 'OSM/StreamParser' +locations = nil + class OSMTestParserCallbacks < OSM::Callbacks - @@locations = nil + locations = nil def self.locations - if @@locations - @@locations + if locations + locations else #parse the test file, so we can later reference nodes and ways by name in tests - @@locations = {} + locations = {} file = 'test/data/test.osm' callbacks = OSMTestParserCallbacks.new parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks) parser.parse - puts @@locations + puts locations end end def node(node) - @@locations[node.name] = [node.lat,node.lon] + locations[node.name] = [node.lat,node.lon] end end \ No newline at end of file