Class: TLDR::Runner
- Inherits:
-
Object
- Object
- TLDR::Runner
- Defined in:
- lib/tldr/runner.rb
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #instantiate_reporter(config) ⇒ Object
- #run(config, plan) ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 |
# File 'lib/tldr/runner.rb', line 5 def initialize @executor = Executor.new @wip = Concurrent::Array.new @results = Concurrent::Array.new @run_aborted = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#instantiate_reporter(config) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tldr/runner.rb', line 12 def instantiate_reporter config begin reporter_class = Kernel.const_get(config.reporter) rescue NameError raise Error, "Unknown reporter '#{config.reporter}' (are you sure it was loaded by your test or helper?)" end if reporter_class.is_a?(Class) if reporter_class.instance_method(:initialize).parameters.any? { |type, _| [:req, :opt, :rest].include?(type) } reporter_class.new(config) else reporter_class.new end else raise Error, "Reporter '#{config.reporter}' expected to be a class, but was a #{reporter_class.class}" end end |
#run(config, plan) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tldr/runner.rb', line 29 def run config, plan @wip.clear @results.clear reporter = instantiate_reporter(config) reporter.before_suite(plan.tests) if reporter.respond_to?(:before_suite) time_bomb = Thread.new { next if config.timeout < 0 explode = proc do next if @run_aborted.true? @run_aborted.make_true @wip.each(&:capture_backtrace_at_exit) reporter.after_tldr(plan.tests, @wip.dup, @results.dup) if reporter.respond_to?(:after_tldr) # If there are failures/errors, use their exit code regardless of exit_0_on_timeout if @results.any? { |result| result.error? || result.failure? } exit!(exit_code(@results, config)) else exit!(config.exit_0_on_timeout ? 0 : 3) end end sleep(config.timeout) # Don't hard-kill the runner if user is debugging, it'll # screw up their terminal slash be a bad time if IRB.CurrentContext IRB.conf[:AT_EXIT] << explode else explode.call end } results = @executor.execute(plan) { |test| run_test(test, config, plan, reporter) }.tap do time_bomb.kill end unless @run_aborted.true? reporter.after_suite(results) if reporter.respond_to?(:after_suite) exit(exit_code(results, config)) end end |