Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / examples / multi_threaded_behaviour_runner.rb
blobe2824a61e0b171d20f1c673d4649157827ff04e7
2 class MultiThreadedBehaviourRunner < Spec::Runner::BehaviourRunner
3   def initialize(options)
4     super
5     # configure these
6     @thread_count = 4
7     @thread_wait = 0
8   end
10   def run_behaviours(behaviours)
11     @threads = []
12     q = Queue.new
13     behaviours.each { |b| q << b}
14     @thread_count.times do
15       @threads << Thread.new(q) do |queue|
16         while not queue.empty?
17           behaviour = queue.pop
18           behaviour.run(@options.reporter, @options.dry_run, @options.reverse)
19         end
20       end
21       sleep @thread_wait
22     end
23     @threads.each {|t| t.join}
24   end
25 end