Class: Turn::MiniRunner

Inherits:
MiniTest::Unit
  • Object
show all
Defined in:
lib/turn/runners/minirunner.rb

Overview

Turn’s MiniTest test runner class.

Instance Method Summary collapse

Constructor Details

#initializeMiniRunner

Returns a new instance of MiniRunner.



15
16
17
18
19
20
21
22
23
# File 'lib/turn/runners/minirunner.rb', line 15

def initialize
  @turn_config = Turn.config

  super()

  # route minitests traditional output to nowhere
  # (instead of overriding #puts and #print)
  @@out = ::StringIO.new
end

Instance Method Details

#_run_suite(suite, type) ⇒ Object

Override #_run_suite to iterate tests via Turn.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/turn/runners/minirunner.rb', line 65

def _run_suite suite, type
  # suites are cases in minitest
  @turn_case = @turn_suite.new_case(suite.name)

  filter = @options[:filter] || @turn_config.pattern || /./

  suite.send("#{type}_methods").grep(filter).each do |test|
    @turn_case.new_test(test)
  end

  turn_reporter.start_case(@turn_case)

  header = "#{type}_suite_header"
  puts send(header, suite) if respond_to? header

  assertions = @turn_case.tests.map do |test|
    @turn_test = test
    turn_reporter.start_test(@turn_test)

    inst = suite.new(test.name) #method
    inst._assertions = 0

    result = inst.run self

    if result == "."
      turn_reporter.pass
    end

    turn_reporter.finish_test(@turn_test)

    inst._assertions
  end

  @turn_case.count_assertions = assertions.inject(0) { |sum, n| sum + n }

  turn_reporter.finish_case(@turn_case)

  return assertions.size, assertions.inject(0) { |sum, n| sum + n }
end

#_run_suites(suites, type) ⇒ Object

Override #_run_suite to setup Turn.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/turn/runners/minirunner.rb', line 42

def _run_suites suites, type
  # Someone want to explain to me why these are fucking here?
  suites = suites - [MiniTest::Spec]
  suites = suites - [Test::Unit::TestCase] if defined?(Test::Unit::TestCase)

  @turn_suite = Turn::TestSuite.new(@turn_config.suite_name)
  @turn_suite.size = suites.size  #::MiniTest::Unit::TestCase.test_suites.size
  @turn_suite.seed = ::MiniTest::Unit.runner.options[:seed]

  turn_reporter.start_suite(@turn_suite)

  if @turn_config.matchcase
    suites = suites.select{ |suite| @turn_config.matchcase =~ suite.name }
  end

  result = suites.map { |suite| _run_suite(suite, type) }

  turn_reporter.finish_suite(@turn_suite)

  return result
end

#puke(klass, meth, err) ⇒ Object

Override #puke to update Turn’s internals and reporter.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/turn/runners/minirunner.rb', line 106

def puke(klass, meth, err)
  case err
  when MiniTest::Skip
    @turn_test.skip!(err)
    turn_reporter.skip(err)
  when MiniTest::Assertion
    @turn_test.fail!(err)
    turn_reporter.fail(err)
  else
    @turn_test.error!(err)
    turn_reporter.error(err)
  end
  super(klass, meth, err)
end

#start(args = []) ⇒ Object

Turn calls this method to start the test run.



31
32
33
34
35
36
37
38
39
# File 'lib/turn/runners/minirunner.rb', line 31

def start(args=[])
  # minitest changed #run in 6023c879cf3d5169953e on April 6th, 2011
  if ::MiniTest::Unit.respond_to?(:runner=)
    ::MiniTest::Unit.runner = self
  end
  # FIXME: why isn't @test_count set?
  run(args)
  return @turn_suite
end

#turn_reporterObject



26
27
28
# File 'lib/turn/runners/minirunner.rb', line 26

def turn_reporter
  @turn_config.reporter
end