test/functional/storage_helper.rb in ruote-2.2.0 vs test/functional/storage_helper.rb in ruote-2.3.0

- old
+ new

@@ -4,27 +4,29 @@ # # since Mon Oct 9 22:19:44 JST 2006 # require 'ruote/storage/hash_storage' -require 'ruote/storage/fs_storage' -def locate_storage_impl (arg) +def locate_storage_impl(pers) - pers = arg[2..-1] + glob = File.expand_path("../../../../ruote-#{pers}*", __FILE__) - path = Dir[File.expand_path( - File.join(File.dirname(__FILE__), %w[ .. .. .. ], "ruote-#{pers}*"))].first + path = Dir[glob].first - File.directory?(path) ? [ pers, path ] : nil + if path + File.directory?(path) ? [ pers, path ] : nil + elsif glob.split('/').include?('bundler') + glob.match(/^(.+\/ruote-#{pers}\/).+/) ? [ pers, $~[1] ] : nil + end end +# Returns an instance of the storage to use (the ARGV determines which +# storage to use). # -# Returns the class of the engine to use, based on the ARGV -# -def determine_storage (opts) +def determine_storage(opts) if ARGV.include?('--help') puts %{ ARGUMENTS for functional tests : @@ -37,60 +39,71 @@ exit 0 end ps = ARGV.select { |a| a.match(/^--[a-z]/) } ps.delete('--split') + ps = ps.collect { |s| m = s.match(/^--(.+)$/); m ? m[1] : s } + ps = [ ENV['RUOTE_STORAGE'] ].compact if ps.empty? + + ps = [] if ps == [ 'hash' ] || ps == [ 'memory' ] + persistent = opts.delete(:persistent) - if ps.include?('--fs') + if ps.include?('fs') - begin - require 'yajl' - rescue LoadError - require 'json' - end + require 'ruote/storage/fs_storage' + + require_json Rufus::Json.detect_backend Ruote::FsStorage.new('work', opts) elsif not ps.empty? - pers = nil - ps.find { |a| pers = locate_storage_impl(a) } + pers = ps.inject(nil) { |r, a| r ? r : locate_storage_impl(a) } raise "no persistence found (#{ps.inspect})" unless pers lib, path = pers $:.unshift(File.join(path, 'lib')) - begin - load 'test/functional_connection.rb' - rescue LoadError => le + load_errors = [] + + [ '.', path ].product(%w[ + connection functional_connection integration_connection + ]).each do |pa, f| + + paf = "#{File.join(pa, 'test', f)}.rb" begin - load File.join(path, %w[ test functional_connection.rb ]) - rescue LoadError => lee - begin - load File.join(path, %w[ test integration_connection.rb ]) - rescue LoadError => leee - p le - p lee - p leee - raise leee - end + load(paf) + load_errors = nil + break + rescue LoadError => le + load_errors << [ paf, le ] end end + if load_errors + puts "=" * 80 + puts "** failed to load connection" + load_errors.each do |paf, le| + puts + puts paf + p le + end + puts "=" * 80 + exit(1) + end + new_storage(opts) elsif persistent - begin - require 'yajl' - rescue LoadError - require 'json' - end + require_json Rufus::Json.detect_backend + + require 'ruote/storage/fs_storage' Ruote::FsStorage.new('work', opts) else