Class: Journo::SuiteRunner

Inherits:
MiniTest::Unit
  • Object
show all
Defined in:
lib/journo/suite_runner.rb

Overview

Runner for MiniTest suites.

This is a heavily refactored version of the built-in MiniTest runner. It's about the same speed, from what I can tell, but is significantly easier to extend.

Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSuiteRunner

Returns a new instance of SuiteRunner.



14
15
16
17
18
19
20
21
22
23
# File 'lib/journo/suite_runner.rb', line 14

def initialize
  self.report = {}
  self.errors = 0
  self.failures = 0
  self.skips = 0
  self.test_count = 0
  self.assertion_count = 0
  self.verbose = false
  self.reporters = []
end

Instance Attribute Details

#reporters

Returns the value of attribute reporters.



12
13
14
# File 'lib/journo/suite_runner.rb', line 12

def reporters
  @reporters
end

#suite_start_time

Returns the value of attribute suite_start_time.



12
13
14
# File 'lib/journo/suite_runner.rb', line 12

def suite_start_time
  @suite_start_time
end

#test_start_time

Returns the value of attribute test_start_time.



12
13
14
# File 'lib/journo/suite_runner.rb', line 12

def test_start_time
  @test_start_time
end

Instance Method Details

#_run_anything(type)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/journo/suite_runner.rb', line 25

def _run_anything(type)
  self.start_time = Time.now
  
  suites = suites_of_type(type)
  tests = suites.inject({}) do |acc, suite|
    acc[suite] = filtered_tests(suite, type)
    acc
  end
  
  self.test_count = tests.inject(0) { |acc, suite| acc + suite[1].length }
  
  if test_count > 0
    trigger(:before_suites, suites, type)
    
    fix_sync do
      suites.each { |suite| _run_suite(suite, tests[suite]) }
    end
    
    trigger(:after_suites, suites, type)
  end
end

#_run_suite(suite, tests)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/journo/suite_runner.rb', line 47

def _run_suite(suite, tests)
  unless tests.empty?
    begin
      self.suite_start_time = Time.now
      
      trigger(:before_suite, suite)
      suite.startup if suite.respond_to?(:startup)
      
      tests.each { |test| _run_test(suite, test) }
    ensure
      suite.shutdown if suite.respond_to?(:shutdown)
      trigger(:after_suite, suite)
    end
  end
end

#_run_test(suite, test)



63
64
65
66
67
68
69
70
71
72
# File 'lib/journo/suite_runner.rb', line 63

def _run_test(suite, test)
  self.test_start_time = Time.now
  trigger(:before_test, suite, test)
  
  test_runner = TestRunner.new(suite, test)
  test_runner.run
  add_test_result(suite, test, test_runner)
  
  trigger(test_runner.result, suite, test, test_runner)
end

#trigger(callback, *args)



74
75
76
# File 'lib/journo/suite_runner.rb', line 74

def trigger(callback, *args)
  reporters.each { |reporter| reporter.send(callback, *args) }
end