lib/pork/isolate.rb in pork-1.0.4 vs lib/pork/isolate.rb in pork-1.1.0

- old
+ new

@@ -3,51 +3,54 @@ require 'pork/executor' module Pork module Isolate def all_tests - @all_tests ||= Hash[build_all_tests] + @all_tests ||= build_all_tests end - def isolate name, stat=Stat.new + def isolate path, stat=Stat.new + # XXX: 91152211182a086de20e3e84c96b6befca655975 + # Executor.execute is a no-op when Should is not loaded, + # but if it's loaded, it's essential to call Should#execute to + # setup the stat in thread group. Try to come up a better way! execute(stat) do |s| - execute_with_isolation(all_tests[name], s) + execute_with_isolation(path, s) end end protected - def build_all_tests paths=[] - @tests.flat_map.with_index do |(type, arg, _), index| - current = paths + [index] + def build_all_tests result={}, path=[] + @tests.each_with_index.inject(result) do |r, ((type, arg, _), index)| + current = path + [index] case type when :describe - arg.build_all_tests(current) + arg.build_all_tests(r, current) when :would - [["#{desc.chomp(': ')} #{arg} ##{current}", current]] - else - [] + (r[description_for("would #{arg}")] ||= []) << current end + r end end - def execute_with_isolation paths, stat, super_env=nil + def execute_with_isolation path, stat, super_env=nil env = Env.new(super_env) - idx = paths.first + idx = path.first @tests.first(idx).each do |(type, arg, _)| case type when :before env.before << arg when :after env.after << arg end end - if paths.size == 1 + if path.size == 1 _, desc, test = @tests[idx] run(desc, test, stat, env) else - @tests[idx][1].execute_with_isolation(paths.drop(1), stat, env) + @tests[idx][1].execute_with_isolation(path.drop(1), stat, env) end end end Executor.extend(Isolate)