Class: Crspec::Runner
- Inherits:
-
Object
- Object
- Crspec::Runner
- Defined in:
- lib/crspec/runner.rb
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#failed_examples ⇒ Object
readonly
Returns the value of attribute failed_examples.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#passed_examples ⇒ Object
readonly
Returns the value of attribute passed_examples.
-
#total_duration ⇒ Object
readonly
Returns the value of attribute total_duration.
Instance Method Summary collapse
-
#initialize(concurrency: Etc.nprocessors, formatter: nil) ⇒ Runner
constructor
A new instance of Runner.
- #run(example_groups) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(concurrency: Etc.nprocessors, formatter: nil) ⇒ Runner
Returns a new instance of Runner.
11 12 13 14 15 16 17 18 19 |
# File 'lib/crspec/runner.rb', line 11 def initialize(concurrency: Etc.nprocessors, formatter: nil) @concurrency = concurrency @formatter = formatter || Formatters::ProgressFormatter.new @queue = Thread::Queue.new @passed_examples = [] @failed_examples = [] @mutex = Mutex.new @total_duration = 0 end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
9 10 11 |
# File 'lib/crspec/runner.rb', line 9 def concurrency @concurrency end |
#failed_examples ⇒ Object (readonly)
Returns the value of attribute failed_examples.
9 10 11 |
# File 'lib/crspec/runner.rb', line 9 def failed_examples @failed_examples end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
9 10 11 |
# File 'lib/crspec/runner.rb', line 9 def formatter @formatter end |
#passed_examples ⇒ Object (readonly)
Returns the value of attribute passed_examples.
9 10 11 |
# File 'lib/crspec/runner.rb', line 9 def passed_examples @passed_examples end |
#total_duration ⇒ Object (readonly)
Returns the value of attribute total_duration.
9 10 11 |
# File 'lib/crspec/runner.rb', line 9 def total_duration @total_duration end |
Instance Method Details
#run(example_groups) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/crspec/runner.rb', line 21 def run(example_groups) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @formatter.start example_groups.each { |group| enqueue_examples(group) } workers = Array.new(@concurrency) do |worker_idx| Thread.new do worker_number = worker_idx + 1 Rails::Parallel.setup_worker(worker_number) if defined?(Rails::Parallel) && Rails::Parallel.enabled? Fiber.set_scheduler(Async::Scheduler.new) if defined?(Async::Scheduler) until @queue.empty? example = begin @queue.pop(true) rescue StandardError nil end break unless example execute_example(example) end ensure Rails::Parallel.teardown_worker(worker_number) if defined?(Rails::Parallel) && Rails::Parallel.enabled? end end workers.each(&:join) @total_duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time @formatter.finish self end |
#success? ⇒ Boolean
53 54 55 |
# File 'lib/crspec/runner.rb', line 53 def success? @failed_examples.empty? end |