Class: Turn::MiniRunner

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

Overview

MiniTest TestRunner

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ MiniRunner

Returns a new instance of MiniRunner.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/turn/runners/minirunner.rb', line 17

def initialize(controller)

  controller.loadpath.each{ |path| $: << path } unless controller.live?
  controller.requires.each{ |path| require(path) }

  [controller.files].flatten.each{ |path| require(path) }

  files = [controller.files].flatten
  files.each{ |path| require(path) }   

  # TODO: Better name ?
  @turn_suite_name = files.map{ |path| File.dirname(path).sub(Dir.pwd+'/','') }.uniq.join(',')

  #sub_suites = []
  #ObjectSpace.each_object(Class) do |klass|
  #  if(Test::Unit::TestCase > klass)
  #    sub_suites << klass.suite
  #  end
  #end
  #suite = Test::Unit::TestSuite.new('')  # FIXME: Name?
  #sub_suites.sort_by{|s|s.name}.each{|s| suite << s}

  #suite.tests.each do |c|
  #  pattern = controller.pattern
  #  c.tests.reject! { |t| pattern !~ t.method_name }
  #end

  @turn_logger = controller.reporter

  super()
end

Instance Method Details

#puke(klass, meth, e) ⇒ Object

Overwrite #puke method so that is stores a hash with :message and :exception keys.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/turn/runners/minirunner.rb', line 139

def puke(klass, meth, e)
  result = nil
  msg = case e
      when ::MiniTest::Skip
        @skips += 1
        result = :skip
        e.message
      when ::MiniTest::Assertion
        @failures += 1
        result = :fail
        e.message
      else
        @errors += 1
        result = :error
        "#{e.class}: #{e.message}\n"
      end

  @report << e #{:message => msg, :exception => e}
  result
end

#run(args = []) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/turn/runners/minirunner.rb', line 56

def run(args = [])
  @verbose = true

  filter = if args.first =~ /^(-n|--name)$/ then
             args.shift
             arg = args.shift
             arg =~ /\/(.*)\// ? Regexp.new($1) : arg
           else
             /./ # anything - ^test_ already filtered by #tests
           end

  #@@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"

  start = Time.now

  run_test_suites(filter)

  return failures + errors if @test_count > 0 # or return nil...
end

#run_test_suites(filter = /./) ⇒ Object



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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/turn/runners/minirunner.rb', line 77

def run_test_suites(filter = /./)
  @test_count, @assertion_count = 0, 0
  old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=

  @turn_suite = Turn::TestSuite.new(@turn_suite_name)
  @turn_suite.size = ::MiniTest::Unit::TestCase.test_suites.size
  @turn_logger.start_suite(@turn_suite)

  ::MiniTest::Unit::TestCase.test_suites.each do |kase|

    test_cases = kase.test_methods.grep(filter)

    @turn_case = @turn_suite.new_case(kase.name)

    turn_cases = test_cases.map do |test|
      @turn_case.new_test(test)
    end

    @turn_logger.start_case(@turn_case)

    turn_cases.each do |test|
      #methname, tcase = name.scan(%r/^([^\(]+)\(([^\)]+)\)/o).flatten!
      @turn_test = test #@turn_case.new_test(test)
      @turn_logger.start_test(@turn_test)

      inst = kase.new(test.name)
      inst._assertions = 0

      result = inst.run(self)
      report = @report.last

      case result
      when :pass
        @turn_logger.pass
      when :error
        #trace = ::MiniTest::filter_backtrace(report[:exception].backtrace).first
        @turn_test.error!(report)
        @turn_logger.error(report)
      when :fail
        #trace = ::MiniTest::filter_backtrace(report[:exception].backtrace).first
        @turn_test.fail!(report)
        @turn_logger.fail(report)
      when :skip
        @turn_test.skip! #(report)
        @turn_logger.skip #(report)
      end

      @turn_logger.finish_test(@turn_test)

      @test_count += 1
      @assertion_count += inst._assertions
    end
    @turn_case.count_assertions = @assertion_count  # for lack of a better appraoch
    @turn_logger.finish_case(@turn_case)
  end
  @turn_logger.finish_suite(@turn_suite)
  @@out.sync = old_sync if @@out.respond_to? :sync=
  [@test_count, @assertion_count]
end

#start(args = []) ⇒ Object



50
51
52
53
# File 'lib/turn/runners/minirunner.rb', line 50

def start(args=[])
  run(args)
  return @turn_suite
end