Class: Assert::Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/assert/suite.rb

Defined Under Namespace

Classes: ContextInfo

Constant Summary collapse

TEST_METHOD_REGEX =
/^test./

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Suite

Returns a new instance of Suite.



13
14
15
16
17
18
19
# File 'lib/assert/suite.rb', line 13

def initialize(config)
  @config = config
  @tests = []
  @test_methods = []
  @start_time = 0
  @end_time = 0
end

Instance Attribute Details

#configObject

A suite is a set of tests to run. When a test class subclasses the Context class, that test class is pushed to the suite.



11
12
13
# File 'lib/assert/suite.rb', line 11

def config
  @config
end

#end_timeObject

A suite is a set of tests to run. When a test class subclasses the Context class, that test class is pushed to the suite.



11
12
13
# File 'lib/assert/suite.rb', line 11

def end_time
  @end_time
end

#start_timeObject

A suite is a set of tests to run. When a test class subclasses the Context class, that test class is pushed to the suite.



11
12
13
# File 'lib/assert/suite.rb', line 11

def start_time
  @start_time
end

#test_methodsObject

A suite is a set of tests to run. When a test class subclasses the Context class, that test class is pushed to the suite.



11
12
13
# File 'lib/assert/suite.rb', line 11

def test_methods
  @test_methods
end

#testsObject Also known as: ordered_tests

A suite is a set of tests to run. When a test class subclasses the Context class, that test class is pushed to the suite.



11
12
13
# File 'lib/assert/suite.rb', line 11

def tests
  @tests
end

Instance Method Details

#count(thing) ⇒ Object



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

def count(thing)
  case thing
  when :tests
    test_count
  when :results
    result_count
  when :passed, :pass
    result_count(:pass)
  when :failed, :fail
    result_count(:fail)
  when :ignored, :ignore
    result_count(:ignore)
  when :skipped, :skip
    result_count(:skip)
  when :errored, :error
    result_count(:error)
  else
    0
  end
end

#inspectObject



93
94
95
96
97
# File 'lib/assert/suite.rb', line 93

def inspect
  "#<#{self.class}:#{'0x0%x' % (object_id << 1)}"\
  " test_count=#{self.test_count.inspect}"\
  " result_count=#{self.result_count.inspect}>"
end

#result_count(type = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/assert/suite.rb', line 65

def result_count(type=nil)
  if type
    self.tests.inject(0) do |count, test|
      count += test.result_count(type)
    end
  else
    self.results.size
  end
end

#result_rateObject



29
30
31
# File 'lib/assert/suite.rb', line 29

def result_rate
  get_rate(self.results.size, self.run_time)
end

#resultsObject Also known as: ordered_results



35
36
37
# File 'lib/assert/suite.rb', line 35

def results
  tests.inject([]) {|results, test| results += test.results}
end

#run_timeObject



21
22
23
# File 'lib/assert/suite.rb', line 21

def run_time
  @end_time - @start_time
end

#setup(&block) ⇒ Object Also known as: startup



75
76
77
78
79
80
81
# File 'lib/assert/suite.rb', line 75

def setup(&block)
  if block_given?
    self.setups << block
  else
    self.setups.each{ |setup| setup.call }
  end
end

#teardown(&block) ⇒ Object Also known as: shutdown



84
85
86
87
88
89
90
# File 'lib/assert/suite.rb', line 84

def teardown(&block)
  if block_given?
    self.teardowns << block
  else
    self.teardowns.reverse.each{ |teardown| teardown.call }
  end
end

#test_countObject



61
62
63
# File 'lib/assert/suite.rb', line 61

def test_count
  self.tests.size
end

#test_rateObject



25
26
27
# File 'lib/assert/suite.rb', line 25

def test_rate
  get_rate(self.tests.size, self.run_time)
end