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'
- 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.
35 36 37 38 |
# File 'lib/gunit/test_runner.rb', line 35 def initialize(*args) STDOUT.sync = true reset end |
Instance Attribute Details
#autorun=(value) ⇒ Object (writeonly)
Sets the attribute autorun
32 33 34 |
# File 'lib/gunit/test_runner.rb', line 32 def autorun=(value) @autorun = value end |
#io ⇒ Object
TestSuites and/or TestCases
31 32 33 |
# File 'lib/gunit/test_runner.rb', line 31 def io @io end |
#patterns ⇒ Object
TestSuites and/or TestCases
31 32 33 |
# File 'lib/gunit/test_runner.rb', line 31 def patterns @patterns end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
33 34 35 |
# File 'lib/gunit/test_runner.rb', line 33 def responses @responses end |
#silent ⇒ Object
TestSuites and/or TestCases
31 32 33 |
# File 'lib/gunit/test_runner.rb', line 31 def silent @silent end |
#tests ⇒ Object
55 56 57 |
# File 'lib/gunit/test_runner.rb', line 55 def tests @tests ||= [] end |
Instance Method Details
#autorun? ⇒ Boolean
59 60 61 |
# File 'lib/gunit/test_runner.rb', line 59 def autorun? ! @autorun.nil? && @autorun end |
#discover ⇒ Object
49 50 51 52 53 |
# File 'lib/gunit/test_runner.rb', line 49 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
99 100 101 |
# File 'lib/gunit/test_runner.rb', line 99 def exceptions @responses.find_all{|r| r.is_a? ExceptionResponse } end |
#fails ⇒ Object
95 96 97 |
# File 'lib/gunit/test_runner.rb', line 95 def fails @responses.find_all{|r| r.is_a? FailResponse } end |
#passes ⇒ Object
91 92 93 |
# File 'lib/gunit/test_runner.rb', line 91 def passes @responses.find_all{|r| r.is_a? PassResponse } end |
#reset ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/gunit/test_runner.rb', line 40 def reset @io = STDOUT @silent = false @responses = [] @tests = [] @patterns = DEFAULT_PATTERNS @autorun = true end |
#run ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gunit/test_runner.rb', line 67 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 "" @responses.each do |response| @io.puts "#{response.} (#{response.file_name}:#{response.line_number})" unless response.is_a?(GUnit::PassResponse) end @io.puts "#{@responses.length} verifications: #{passes.length} passed, #{fails.length} failed, #{exceptions.length} exceptions, #{to_dos.length} to-dos" end end |
#run! ⇒ Object
63 64 65 |
# File 'lib/gunit/test_runner.rb', line 63 def run! self.run if self.autorun? end |
#to_dos ⇒ Object
103 104 105 |
# File 'lib/gunit/test_runner.rb', line 103 def to_dos @responses.find_all{|r| r.is_a? ToDoResponse } end |