Class: GUnit::TestRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/gunit/test_runner.rb

Overview

A TestRunner object discovers TestCase classes The TestRunner object calls suite() on all TestCase classes Each TestCase class returns a TestSuite object with instances of itself (TestCases) each with a method to be executed The TestRunner object calls run() on all TestSuite objects, collecting TestResponses Each TestSuite object calls run() on all of its TestCase objects, yielding TestResponses Each TestCase object executes its method, returning a TestResponse The TestRunner displays the TestResponses as they are yielded After all tests have run, the TestRunner displays a summery of results

Constant Summary collapse

PASS_CHAR =
'.'
FAIL_CHAR =
'F'
TODO_CHAR =
'*'
EXCEPTION_CHAR =
'E'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TestRunner

Returns a new instance of TestRunner.



29
30
31
32
33
34
# File 'lib/gunit/test_runner.rb', line 29

def initialize(*args)
  @responses = []
  @io = STDOUT
  STDOUT.sync = true
  @silent = false
end

Instance Attribute Details

#ioObject

TestSuites and/or TestCases



25
26
27
# File 'lib/gunit/test_runner.rb', line 25

def io
  @io
end

#responsesObject (readonly)

Returns the value of attribute responses.



27
28
29
# File 'lib/gunit/test_runner.rb', line 27

def responses
  @responses
end

#silentObject

TestSuites and/or TestCases



25
26
27
# File 'lib/gunit/test_runner.rb', line 25

def silent
  @silent
end

#testsObject



36
37
38
# File 'lib/gunit/test_runner.rb', line 36

def tests
  @tests ||= []
end

Instance Method Details

#exceptionsObject



72
73
74
# File 'lib/gunit/test_runner.rb', line 72

def exceptions
  @responses.find_all{|r| r.is_a? ExceptionResponse }
end

#failsObject



68
69
70
# File 'lib/gunit/test_runner.rb', line 68

def fails
  @responses.find_all{|r| r.is_a? FailResponse }
end

#passesObject



64
65
66
# File 'lib/gunit/test_runner.rb', line 64

def passes
  @responses.find_all{|r| r.is_a? PassResponse }
end

#runObject



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

def run
  self.tests.each do |test|
    case
    when test.is_a?(TestSuite)
      test.run do |response|
        @responses << response
        @io.print self.class.response_character(response) unless self.silent
      end
    when test.is_a?(TestCase)
      response = test.run
      @responses << response
      @io.print self.class.response_character(response) unless self.silent
    end
  end
  
  unless self.silent
    @io.puts ""
    fails.each do |fail|
      @io.puts "#{fail.message} (#{fail.file_name}:#{fail.line_number})"
    end
    @io.puts "#{@responses.length} verifications: #{passes.length} passed, #{fails.length} failed, #{exceptions.length} exceptions, #{to_dos.length} to-dos"
  end
end

#to_dosObject



76
77
78
# File 'lib/gunit/test_runner.rb', line 76

def to_dos
  @responses.find_all{|r| r.is_a? ToDoResponse }
end