Class: RubyUnit::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/RubyUnit/Runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



16
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
# File 'lib/RubyUnit/Runner.rb', line 16

def run
  @@start = Time.new
  runner = new
  TestCase.descendents.each do |object|
    @@test_cases << object

    data_methods = object.instance_methods.grep /Data\Z/
    test_methods = object.instance_methods.grep /Test\Z/

    test_methods.each do |test|
      data_method = "#{test.slice(0..-5)}Data".to_sym
      if data_methods.include? data_method
        test_case = object.new
        data      = test_case.send data_method

        raise "Data method #{data_method} must return an array" unless data.is_a? Array
        data.each do |params|
          raise "Data method #{data_method} must return an array of arrays" unless data.is_a? Array
          runner.run object, test, params
        end
      else
        runner.run object, test
      end
    end
  end
  @@finish = Time.new
  report
end

Instance Method Details

#run(object, test, params = []) ⇒ Object

Raises:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/RubyUnit/Runner.rb', line 75

def run object, test, params = []
  raise ArgumentError, "Parameter list for #{object.class}::#{test} must be an array" unless params.is_a? Array

  test_case = object.new

  begin
    @@tests += 1
    test_case.setup
    test_case.send test, *params
  rescue AssertionFailure => failure
    @@failures << [test_case.class.name, test, params, failure]
  rescue Exception => error
    @@errors << [test_case.class.name, test, params, error]
  ensure
    test_case.teardown
  end
end