Class: Test::Unit::TestSuite

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name = "Unnamed TestSuite") ⇒ TestSuite

Creates a new TestSuite with the given name.



24
25
26
27
# File 'lib/test/unit/testsuite.rb', line 24

def initialize(name="Unnamed TestSuite")
  @name = name
  @tests = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/test/unit/testsuite.rb', line 18

def name
  @name
end

#testsObject (readonly)

Returns the value of attribute tests.



18
19
20
# File 'lib/test/unit/testsuite.rb', line 18

def tests
  @tests
end

Instance Method Details

#<<(test) ⇒ Object

Adds the test to the suite.



40
41
42
43
# File 'lib/test/unit/testsuite.rb', line 40

def <<(test)
  @tests << test
  self
end

#==(other) ⇒ Object

It’s handy to be able to compare TestSuite instances.



69
70
71
72
73
# File 'lib/test/unit/testsuite.rb', line 69

def ==(other)
  return false unless(other.kind_of?(self.class))
  return false unless(@name == other.name)
  @tests == other.tests
end

#delete(test) ⇒ Object



45
46
47
# File 'lib/test/unit/testsuite.rb', line 45

def delete(test)
  @tests.delete(test)
end

#empty?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/test/unit/testsuite.rb', line 58

def empty?
  tests.empty?
end

#run(result) {|STARTED, name| ... } ⇒ Object

Runs the tests and/or suites contained in this TestSuite.

Yields:



31
32
33
34
35
36
37
# File 'lib/test/unit/testsuite.rb', line 31

def run(result, &progress_block)
  yield(STARTED, name)
  @tests.each do |test|
    test.run(result, &progress_block)
  end
  yield(FINISHED, name)
end

#sizeObject

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.



52
53
54
55
56
# File 'lib/test/unit/testsuite.rb', line 52

def size
  total_size = 0
  @tests.each { |test| total_size += test.size }
  total_size
end

#to_sObject

Overridden to return the name given the suite at creation.



64
65
66
# File 'lib/test/unit/testsuite.rb', line 64

def to_s
  @name
end