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

#initializeSuite

Returns a new instance of Suite.



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

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

Instance Attribute Details

#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.



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

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.



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

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.



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

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.



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

def tests
  @tests
end

Instance Method Details

#count(thing) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/assert/suite.rb', line 46

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

#result_count(type = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/assert/suite.rb', line 71

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

#resultsObject Also known as: ordered_results



41
42
43
# File 'lib/assert/suite.rb', line 41

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

#run_timeObject



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

def run_time
  @end_time - @start_time
end

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



81
82
83
84
85
86
87
# File 'lib/assert/suite.rb', line 81

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



90
91
92
93
94
95
96
# File 'lib/assert/suite.rb', line 90

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

#test_countObject



67
68
69
# File 'lib/assert/suite.rb', line 67

def test_count
  self.tests.size
end