Class: DeepTest::Test::SupervisedTestSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/test/supervised_test_suite.rb

Instance Method Summary collapse

Constructor Details

#initialize(suite, blackboard) ⇒ SupervisedTestSuite

Returns a new instance of SupervisedTestSuite.



4
5
6
7
# File 'lib/deep_test/test/supervised_test_suite.rb', line 4

def initialize(suite, blackboard)
  @suite = suite
  @blackboard = blackboard
end

Instance Method Details

#add_tests(test_suite, tests_by_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/deep_test/test/supervised_test_suite.rb', line 21

def add_tests(test_suite, tests_by_name)
  if test_suite.respond_to? :tests
    test_suite.tests.each do |test| 
      add_tests(test, tests_by_name)
    end
  else
    tests_by_name[test_suite.name] = test_suite
    @blackboard.write_work Test::WorkUnit.new(test_suite)
  end
end

#read_results(result, tests_by_name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/deep_test/test/supervised_test_suite.rb', line 32

def read_results(result, tests_by_name)
  DeepTest.logger.debug("SupervisedTestSuite: going to read #{tests_by_name.size} results")

  result_times = {}
  
  missing_tests = 
    ResultReader.new(@blackboard).read(tests_by_name) do |test, remote_result|
      result_times["#{test.method_name}(#{test.class.name}) #{remote_result.host}"] = remote_result.time
      remote_result.add_to result
      yield ::Test::Unit::TestCase::FINISHED, test.name if block_given?
    end
  
  longest_test_name_size = result_times.keys.map(&:size).sort.last
  if File.exist? "tmp"
    File.open(File.join("tmp", "test_times.txt"), "w") do |file|
      file.write result_times.sort_by {|n, t| t}.reverse.map {|n, t| n.ljust(longest_test_name_size + 1) + t.to_s.sub(/^(.*\.\d)\d.*/, '\1').rjust(9) + "\n"}.join
    end
  end

  missing_tests.each do |name, test_case|
    result.add_error ::Test::Unit::Error.new(name, WorkUnitNeverReceivedError.new)
  end
ensure
  DeepTest.logger.debug("SupervisedTestSuite: exiting with #{missing_tests.size} results left")
end

#run(result) {|::Test::Unit::TestSuite::STARTED, @suite.name| ... } ⇒ Object

Yields:

  • (::Test::Unit::TestSuite::STARTED, @suite.name)


9
10
11
12
13
14
15
# File 'lib/deep_test/test/supervised_test_suite.rb', line 9

def run(result, &progress_block)
  yield ::Test::Unit::TestSuite::STARTED, @suite.name
  tests_by_name = {}
  add_tests @suite, tests_by_name
  read_results result, tests_by_name, &progress_block
  yield ::Test::Unit::TestSuite::FINISHED, @suite.name
end

#sizeObject



17
18
19
# File 'lib/deep_test/test/supervised_test_suite.rb', line 17

def size
  @suite.size
end