Class: Test::Unit::TestSuite
- Inherits:
-
Object
- Object
- Test::Unit::TestSuite
- Defined in:
- lib/test/unit/testsuite.rb
Overview
A collection of tests which can be #run.
Note: It is easy to confuse a TestSuite instance with something that has a static suite method; I know because I have trouble keeping them straight. Think of something that has a suite method as simply providing a way to get a meaningful TestSuite instance.
Constant Summary collapse
- STARTED =
name + "::STARTED"
- FINISHED =
name + "::FINISHED"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Instance Method Summary collapse
-
#<<(test) ⇒ Object
Adds the test to the suite.
-
#==(other) ⇒ Object
It’s handy to be able to compare TestSuite instances.
- #delete(test) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name = "Unnamed TestSuite", test_case = nil) ⇒ TestSuite
constructor
Creates a new TestSuite with the given name.
-
#run(result) {|STARTED, name| ... } ⇒ Object
Runs the tests and/or suites contained in this TestSuite.
-
#size ⇒ Object
Retuns the rolled up number of tests in this suite; i.e.
-
#to_s ⇒ Object
Overridden to return the name given the suite at creation.
Constructor Details
#initialize(name = "Unnamed TestSuite", test_case = nil) ⇒ TestSuite
Creates a new TestSuite with the given name.
26 27 28 29 30 |
# File 'lib/test/unit/testsuite.rb', line 26 def initialize(name="Unnamed TestSuite", test_case=nil) @name = name @tests = [] @test_case = test_case end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/test/unit/testsuite.rb', line 20 def name @name end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
20 21 22 |
# File 'lib/test/unit/testsuite.rb', line 20 def tests @tests end |
Instance Method Details
#<<(test) ⇒ Object
Adds the test to the suite.
45 46 47 48 |
# File 'lib/test/unit/testsuite.rb', line 45 def <<(test) @tests << test self end |
#==(other) ⇒ Object
It’s handy to be able to compare TestSuite instances.
74 75 76 77 78 |
# File 'lib/test/unit/testsuite.rb', line 74 def ==(other) return false unless(other.kind_of?(self.class)) return false unless(@name == other.name) @tests == other.tests end |
#delete(test) ⇒ Object
50 51 52 |
# File 'lib/test/unit/testsuite.rb', line 50 def delete(test) @tests.delete(test) end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/test/unit/testsuite.rb', line 63 def empty? tests.empty? end |
#run(result) {|STARTED, name| ... } ⇒ Object
Runs the tests and/or suites contained in this TestSuite.
34 35 36 37 38 39 40 41 42 |
# File 'lib/test/unit/testsuite.rb', line 34 def run(result, &progress_block) yield(STARTED, name) run_startup(result) @tests.each do |test| test.run(result, &progress_block) end run_shutdown(result) yield(FINISHED, name) end |
#size ⇒ Object
Retuns the rolled up number of tests in this suite; i.e. if the suite contains other suites, it counts the tests within those suites, not the suites themselves.
57 58 59 60 61 |
# File 'lib/test/unit/testsuite.rb', line 57 def size total_size = 0 @tests.each { |test| total_size += test.size } total_size end |
#to_s ⇒ Object
Overridden to return the name given the suite at creation.
69 70 71 |
# File 'lib/test/unit/testsuite.rb', line 69 def to_s @name end |