Class: ThreadedRspec::ExampleGroupRunner

Inherits:
Spec::Runner::ExampleGroupRunner
  • Object
show all
Defined in:
lib/threaded_rspec/example_group_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, thread_count) ⇒ ExampleGroupRunner



3
4
5
6
7
# File 'lib/threaded_rspec/example_group_runner.rb', line 3

def initialize(options, thread_count)
  super(options)
  @options = options
  @thread_count = thread_count.to_i
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/threaded_rspec/example_group_runner.rb', line 9

def run
  prepare
  queue = Queue.new
  example_groups.each{|g| queue << g}

  success = true
  threads = []
  @thread_count.times do
    threads << Thread.new do
      success &= queue.pop.run(@options) while !queue.empty?
    end
  end
  threads.each{|t| t.join}

  success
ensure
  finish
end