Class: Lax::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/lax/runner.rb

Overview

Runner for test cases. Handles callbacks, concurrency, etc. TODO: DRb support!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cases, opts = {}) ⇒ Runner

Takes an array of test cases and an optional hash of options.



7
8
9
# File 'lib/lax/runner.rb', line 7

def initialize(cases, opts={})
  @cases, @opts = cases, {threads: 1}.merge(opts)
end

Instance Attribute Details

#casesObject (readonly)

Returns the value of attribute cases.



5
6
7
# File 'lib/lax/runner.rb', line 5

def cases
  @cases
end

Instance Method Details

#goObject



11
12
13
14
15
16
17
18
19
# File 'lib/lax/runner.rb', line 11

def go
  (start=@opts[:start]) and start[self]
  todo = @cases.dup
  (1..@opts[:threads]).map do
    Thread.new {after run before todo.shift while todo.any?}
  end.each &:join
  (finish=@opts[:finish]) and finish[self]
  self
end