Class: MicroTest::Runner

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter, options = {}) ⇒ Runner

Returns a new instance of Runner.



12
13
14
15
16
# File 'lib/micro_test/runner.rb', line 12

def initialize(formatter, options={})
  @formatter = formatter
  @options = options
  reset
end

Class Attribute Details

.exitObject

Returns the value of attribute exit.



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

def exit
  @exit
end

Instance Attribute Details

#active_testObject (readonly)

Returns the value of attribute active_test.



10
11
12
# File 'lib/micro_test/runner.rb', line 10

def active_test
  @active_test
end

#durationObject (readonly)

Returns the value of attribute duration.



10
11
12
# File 'lib/micro_test/runner.rb', line 10

def duration
  @duration
end

#failedObject (readonly)

Returns the value of attribute failed.



10
11
12
# File 'lib/micro_test/runner.rb', line 10

def failed
  @failed
end

#formatterObject (readonly)

Returns the value of attribute formatter.



10
11
12
# File 'lib/micro_test/runner.rb', line 10

def formatter
  @formatter
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/micro_test/runner.rb', line 10

def options
  @options
end

#passedObject (readonly)

Returns the value of attribute passed.



10
11
12
# File 'lib/micro_test/runner.rb', line 10

def passed
  @passed
end

Instance Method Details

#resetObject



48
49
50
51
52
# File 'lib/micro_test/runner.rb', line 48

def reset
  @duration = 0
  @passed = 0
  @failed = 0
end

#runObject



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
# File 'lib/micro_test/runner.rb', line 18

def run
  test_classes = MicroTest::Test.subclasses.shuffle
  tests = test_classes.map{ |klass| klass.tests }.flatten
  formatter.before_suite(test_classes)
  start = Time.now

  test_classes.each do |test_class|
    formatter.before_class(test_class)
    test_class.tests.shuffle.each do |test|
      @active_test = test
      if @options[:async]
        @tests ||= Queue.new
        @tests << test
      else
        test.invoke(@formatter, @options)
      end
    end
    formatter.after_class(test_class)
  end

  run_threads if @options[:async]

  @duration = Time.now - start
  @passed = tests.select{ |test| test.passed? }.count
  @failed = tests.select{ |test| !test.passed? }.count
  formatter.after_results(self)
  formatter.after_suite(test_classes)
  @failed
end