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.



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

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.



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

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.



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

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.



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

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.



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

def tests
  @tests
end

Instance Method Details

#count(thing) ⇒ Object



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

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



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

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



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

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

#run_timeObject



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

def run_time
  @end_time - @start_time
end

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



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

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



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

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

#test_countObject



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

def test_count
  self.tests.size
end