class PryTest::Runner
Attributes
duration[R]
formatter[R]
options[R]
Public Class Methods
new(formatter, options = {})
click to toggle source
# File lib/pry-test/runner.rb, line 18 def initialize(formatter, options = {}) @formatter = formatter @options = options end
terminate()
click to toggle source
# File lib/pry-test/runner.rb, line 7 def terminate @terminate = true end
terminate?()
click to toggle source
# File lib/pry-test/runner.rb, line 11 def terminate? !!@terminate end
Public Instance Methods
failed()
click to toggle source
# File lib/pry-test/runner.rb, line 42 def failed failed_tests.length end
failed_tests()
click to toggle source
# File lib/pry-test/runner.rb, line 38 def failed_tests tests.select { |test| test.invoked? && !test.passed? } end
passed()
click to toggle source
# File lib/pry-test/runner.rb, line 50 def passed passed_tests.length end
passed_tests()
click to toggle source
# File lib/pry-test/runner.rb, line 46 def passed_tests tests.select { |test| test.invoked? && test.passed? } end
run()
click to toggle source
# File lib/pry-test/runner.rb, line 23 def run formatter.before_suite(test_classes) run_test_classes formatter.after_suite(test_classes) failed end
test_classes()
click to toggle source
# File lib/pry-test/runner.rb, line 30 def test_classes @test_classes ||= PryTest::Test.subclasses.shuffle end
tests()
click to toggle source
# File lib/pry-test/runner.rb, line 34 def tests @tests ||= test_classes.map { |klass| klass.tests }.flatten end
Private Instance Methods
run_test_class(test_class, queue)
click to toggle source
# File lib/pry-test/runner.rb, line 67 def run_test_class(test_class, queue) return if PryTest::Runner.terminate? formatter.before_class(test_class) test_class.tests.shuffle.each do |test| if options[:async] queue << test else test.invoke(formatter, options) end end formatter.after_class(test_class) end
run_test_classes()
click to toggle source
# File lib/pry-test/runner.rb, line 56 def run_test_classes start = Time.now queue ||= Queue.new if options[:async] test_classes.each do |test_class| run_test_class test_class, queue end run_threads(queue) if options[:async] @duration = Time.now - start formatter.after_results(self) end
run_threads(queue)
click to toggle source
# File lib/pry-test/runner.rb, line 85 def run_threads(queue) puts "PryTest is running #{thread_count} threads." threads = thread_count.times.map { Thread.new do until queue.empty? Thread.current.terminate if PryTest::Runner.terminate? test = queue.pop test.invoke(formatter, options) end end } threads.each { |t| t.join } end
thread_count()
click to toggle source
# File lib/pry-test/runner.rb, line 80 def thread_count count = OS.cpu_count count < 2 ? 2 : count end