]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/examples/pure/multi_threaded_behaviour_runner.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / examples / pure / multi_threaded_behaviour_runner.rb
1 class MultiThreadedExampleGroupRunner < Spec::Runner::ExampleGroupRunner
2   def initialize(options, arg)
3     super(options)
4     # configure these
5     @thread_count = 4
6     @thread_wait = 0
7   end
8
9   def run
10     @threads = []
11     q = Queue.new
12     example_groups.each { |b| q << b}
13     success = true
14     @thread_count.times do
15       @threads << Thread.new(q) do |queue|
16         while not queue.empty?
17           example_group = queue.pop
18           success &= example_group.suite.run(nil)
19         end
20       end
21       sleep @thread_wait
22     end
23     @threads.each {|t| t.join}
24     success
25   end
26 end
27
28 MultiThreadedBehaviourRunner = MultiThreadedExampleGroupRunner