Class: Test::Right::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, widgets, features) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
# File 'lib/test/right/runner.rb', line 9

def initialize(config, widgets, features)
  @config = config
  @widget_classes = widgets
  @features = features
  @results = {}
  @pool = Threadz::ThreadPool.new(:initial_size => 2, :maximum_size => 2)
  @result_queue = Queue.new
  @data_template = config[:data] || {}
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

#widget_classesObject (readonly)

Returns the value of attribute widget_classes.



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

def widget_classes
  @widget_classes
end

Instance Method Details

#process_resultsObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/test/right/runner.rb', line 31

def process_results
  failed = false
  until @result_queue.empty?
    feature, method, result = @result_queue.pop
    if result.is_a? Exception
      failed = true
    end
    @results[feature] ||= {}
    @results[feature][method] = result
  end
  return !failed
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/test/right/runner.rb', line 19

def run
  @batch = @pool.new_batch

  @features.sort_by{|x| rand(10000)}.all? do |feature|
    run_feature(feature)
  end

  @batch.wait_until_done

  process_results
end

#run_feature(feature) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/test/right/runner.rb', line 44

def run_feature(feature)
  methods = feature.instance_methods
  methods.sort_by{|x| rand(10000)}.each do |method_name|
    if method_name =~ /^test_/
      @batch << Proc.new do
        begin
          method = method_name.to_sym
          run_test(feature, method_name.to_sym)

          @result_queue << [feature, method, true]
        rescue => e
          @result_queue << [feature, method, e]
        end
      end
    end
  end
end

#run_test(feature, method) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/test/right/runner.rb', line 62

def run_test(feature, method)
  if $MOCK_DRIVER
    driver = MockDriver.new(@config)
  else
    driver = BrowserDriver.new(@config)
  end

  data = DataFactory.new(@data_template)

  begin
    target = feature.new(driver, data)
    if target.respond_to? :setup
      target.setup
    end
    target.send(method)
  ensure
    driver.quit
  end
end