Class: GUnit::TestRunner
- Inherits:
-
Object
- Object
- GUnit::TestRunner
- Includes:
- Singleton
- 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'
- PASS_COLOR =
"\e[0;32m"
- FAIL_COLOR =
"\e[0;31m"
- EXCEPTION_COLOR =
"\e[0;31m"
- TODO_COLOR =
"\e[0;33m"
- DEFAULT_COLOR =
"\e[0m"
- DEFAULT_PATTERNS =
['test/**/*_test.rb', 'test/**/test_*.rb']
Instance Attribute Summary collapse
-
#autorun ⇒ Object
writeonly
Sets the attribute autorun.
-
#io ⇒ Object
TestSuites and/or TestCases.
-
#patterns ⇒ Object
TestSuites and/or TestCases.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#silent ⇒ Object
TestSuites and/or TestCases.
- #tests ⇒ Object
Instance Method Summary collapse
- #autorun? ⇒ Boolean
- #discover ⇒ Object
- #exceptions ⇒ Object
- #fails ⇒ Object
-
#initialize(*args) ⇒ TestRunner
constructor
A new instance of TestRunner.
- #passes ⇒ Object
- #reset ⇒ Object
- #run ⇒ Object
- #run! ⇒ Object
- #to_dos ⇒ Object
Constructor Details
#initialize(*args) ⇒ TestRunner
Returns a new instance of TestRunner.
40 41 42 43 |
# File 'lib/gunit/test_runner.rb', line 40 def initialize(*args) STDOUT.sync = true reset end |
Instance Attribute Details
#autorun=(value) ⇒ Object (writeonly)
Sets the attribute autorun
37 38 39 |
# File 'lib/gunit/test_runner.rb', line 37 def autorun=(value) @autorun = value end |
#io ⇒ Object
TestSuites and/or TestCases
36 37 38 |
# File 'lib/gunit/test_runner.rb', line 36 def io @io end |
#patterns ⇒ Object
TestSuites and/or TestCases
36 37 38 |
# File 'lib/gunit/test_runner.rb', line 36 def patterns @patterns end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
38 39 40 |
# File 'lib/gunit/test_runner.rb', line 38 def responses @responses end |
#silent ⇒ Object
TestSuites and/or TestCases
36 37 38 |
# File 'lib/gunit/test_runner.rb', line 36 def silent @silent end |
#tests ⇒ Object
60 61 62 |
# File 'lib/gunit/test_runner.rb', line 60 def tests @tests ||= [] end |
Instance Method Details
#autorun? ⇒ Boolean
64 65 66 |
# File 'lib/gunit/test_runner.rb', line 64 def autorun? ! @autorun.nil? && @autorun end |
#discover ⇒ Object
54 55 56 57 58 |
# File 'lib/gunit/test_runner.rb', line 54 def discover files = self.patterns.inject([]){|memo, pattern| memo + Dir.glob(pattern) }.compact files.each {|file| Kernel.require file } self.tests = TestCase.subclasses.inject([]){|memo, test_case| memo << test_case.suite }.compact end |
#exceptions ⇒ Object
105 106 107 |
# File 'lib/gunit/test_runner.rb', line 105 def exceptions @responses.find_all{|r| r.is_a? ExceptionResponse } end |
#fails ⇒ Object
101 102 103 |
# File 'lib/gunit/test_runner.rb', line 101 def fails @responses.find_all{|r| r.is_a? FailResponse } end |
#passes ⇒ Object
97 98 99 |
# File 'lib/gunit/test_runner.rb', line 97 def passes @responses.find_all{|r| r.is_a? PassResponse } end |
#reset ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/gunit/test_runner.rb', line 45 def reset @io = STDOUT @silent = false @responses = [] @tests = [] @patterns = DEFAULT_PATTERNS @autorun = true end |
#run ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gunit/test_runner.rb', line 72 def run @io.puts test_case_classes.map{|klass| klass.to_s }.join(', ') unless self.silent self.test_cases.each do |test_case| response = test_case.run @responses << response unless self.silent @io.print self.class.response_color(response) @io.print self.class.response_character(response) @io.print DEFAULT_COLOR end end unless self.silent @io.puts "" @responses.each do |response| unless response.is_a?(GUnit::PassResponse) @io.print self.class.response_color(response) @io.print "#{response.} (#{response.file_name}:#{response.line_number})\n" @io.print DEFAULT_COLOR end end @io.puts "#{@responses.length} verifications: #{passes.length} passed, #{fails.length} failed, #{exceptions.length} exceptions, #{to_dos.length} to-dos" end end |
#run! ⇒ Object
68 69 70 |
# File 'lib/gunit/test_runner.rb', line 68 def run! self.run if self.autorun? end |
#to_dos ⇒ Object
109 110 111 |
# File 'lib/gunit/test_runner.rb', line 109 def to_dos @responses.find_all{|r| r.is_a? ToDoResponse } end |