lib/pork/imp.rb in pork-1.1.3 vs lib/pork/imp.rb in pork-1.2.0
- old
+ new
@@ -26,17 +26,17 @@
def would desc=:default, &test
@tests << [:would, desc, test]
end
- def execute stat=Stat.new
- if block_given?
- yield(stat) # XXX: see Isolate#isolate
- else
- execute_with_parent(stat)
+ def execute mode, *args
+ require "pork/mode/#{mode}"
+ if args.size == 1 || mode.to_s != 'sequential'
+ send(mode, *args)
+ else # cannot run sequential tests for specific paths
+ shuffled(*args)
end
- stat
end
private
def init desc=''
@desc, @tests, @stash = desc, [], {}
@@ -44,55 +44,43 @@
end
def run desc, test, stat, env
assertions = stat.assertions
context = new(stat)
- run_protected(desc, stat) do
+ run_protected(desc, stat, test) do
env.run_before(context)
context.instance_eval(&test)
if assertions == stat.assertions
raise Error.new('Missing assertions')
end
stat.case_pass
end
ensure
stat.incr_tests
- run_protected(desc, stat){ env.run_after(context) }
+ run_protected(desc, stat, test){ env.run_after(context) }
end
- def run_protected desc, stat
+ def run_protected desc, stat, test
yield
rescue Error, StandardError => e
case e
when Skip
stat.incr_skips
stat.case_skip
- when Failure
- stat.add_failure(e, description_for("would #{desc}"))
- stat.case_failed
- when Error, StandardError
- stat.add_error( e, description_for("would #{desc}"))
- stat.case_errored
- end
- end
-
- protected
- def execute_with_parent stat, super_env=nil
- env = Env.new(super_env)
- @tests.each do |(type, arg, test)|
- case type
- when :before
- env.before << arg
- when :after
- env.after << arg
- when :describe
- arg.execute_with_parent(stat, env)
- when :would
- run(arg, test, stat, env)
+ else
+ err = [e, description_for("would #{desc}"), test.source_location]
+ case e
+ when Failure
+ stat.add_failure(err)
+ stat.case_failed
+ when Error, StandardError
+ stat.add_error(err)
+ stat.case_errored
end
end
end
+ protected
def search_stash desc
@stash[desc] or @super_executor && @super_executor.search_stash(desc)
end
def description_for name=''