Class: Assert::Suite

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

Overview

This is the base suite. It loads the tests to run in memory and provides methods for these tests that the runner/view uses for handling and presentation purposes. It also stores suite-level setups and teardowns. Override the test/result count methods and the callbacks as needed. See the default suite for example usage.

Direct Known Subclasses

DefaultSuite

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigHelpers

#all_pass?, #formatted_result_rate, #formatted_run_time, #formatted_suite_result_rate, #formatted_suite_run_time, #formatted_suite_test_rate, #formatted_test_rate, #ocurring_result_types, #runner, #runner_seed, #show_test_profile_info?, #show_test_verbose_info?, #single_test?, #single_test_file_line, #view

Constructor Details

#initialize(config) ⇒ Suite

Returns a new instance of Suite.


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

def initialize(config)
  @config     = config
  @tests      = []
  @setups     = []
  @teardowns  = []
  @start_time = Time.now
  @end_time   = @start_time
end

Instance Attribute Details

#configObject (readonly)

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.


18
19
20
# File 'lib/assert/suite.rb', line 18

def config
  @config
end

#end_timeObject

Returns the value of attribute end_time.


19
20
21
# File 'lib/assert/suite.rb', line 19

def end_time
  @end_time
end

#setupsObject (readonly)

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.


18
19
20
# File 'lib/assert/suite.rb', line 18

def setups
  @setups
end

#start_timeObject

Returns the value of attribute start_time.


19
20
21
# File 'lib/assert/suite.rb', line 19

def start_time
  @start_time
end

#teardownsObject (readonly)

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.


18
19
20
# File 'lib/assert/suite.rb', line 18

def teardowns
  @teardowns
end

Instance Method Details

#after_loadObject


111
112
# File 'lib/assert/suite.rb', line 111

def after_load
end

#after_test(test) ⇒ Object


123
124
# File 'lib/assert/suite.rb', line 123

def after_test(test)
end

#before_load(test_files) ⇒ Object

define callback handlers to do special behavior during the test run. These will be called by the test runner.


102
103
# File 'lib/assert/suite.rb', line 102

def before_load(test_files)
end

#before_test(test) ⇒ Object


117
118
# File 'lib/assert/suite.rb', line 117

def before_test(test)
end

#clear_tests_to_runObject


52
53
54
# File 'lib/assert/suite.rb', line 52

def clear_tests_to_run
  @tests.clear
end

#error_result_countObject


76
77
# File 'lib/assert/suite.rb', line 76

def error_result_count
end

#fail_result_countObject


73
74
# File 'lib/assert/suite.rb', line 73

def fail_result_count
end

#find_test_to_run(file_line) ⇒ Object


56
57
58
# File 'lib/assert/suite.rb', line 56

def find_test_to_run(file_line)
  @tests.find{ |t| t.file_line == file_line }
end

#ignore_result_countObject


82
83
# File 'lib/assert/suite.rb', line 82

def ignore_result_count
end

#inspectObject


135
136
137
138
139
# File 'lib/assert/suite.rb', line 135

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

#on_finishObject


126
127
# File 'lib/assert/suite.rb', line 126

def on_finish
end

#on_info(test) ⇒ Object


129
130
# File 'lib/assert/suite.rb', line 129

def on_info(test)
end

#on_interrupt(err) ⇒ Object


132
133
# File 'lib/assert/suite.rb', line 132

def on_interrupt(err)
end

#on_result(result) ⇒ Object


120
121
# File 'lib/assert/suite.rb', line 120

def on_result(result)
end

#on_startObject


114
115
# File 'lib/assert/suite.rb', line 114

def on_start
end

#on_test(test) ⇒ Object

this is required to load tests into the suite, be sure to `super` if you override this method


107
108
109
# File 'lib/assert/suite.rb', line 107

def on_test(test)
  @tests << test
end

#pass_result_countObject


70
71
# File 'lib/assert/suite.rb', line 70

def pass_result_count
end

#result_countObject


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

def result_count
end

#result_rateObject


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

def result_rate
  get_rate(result_count, run_time)
end

#run_timeObject


85
86
87
# File 'lib/assert/suite.rb', line 85

def run_time
  @end_time - @start_time
end

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


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

def setup(&block)
  setups << (block || proc{})
end

#skip_result_countObject


79
80
# File 'lib/assert/suite.rb', line 79

def skip_result_count
end

#sorted_tests_to_run(&sort_by_proc) ⇒ Object


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

def sorted_tests_to_run(&sort_by_proc)
  @tests.sort.sort_by(&sort_by_proc)
end

#suiteObject


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

def suite
  self
end

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


39
40
41
# File 'lib/assert/suite.rb', line 39

def teardown(&block)
  teardowns << (block || proc{})
end

#test_countObject


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

def test_count
end

#test_rateObject


89
90
91
# File 'lib/assert/suite.rb', line 89

def test_rate
  get_rate(test_count, run_time)
end

#tests_to_run?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/assert/suite.rb', line 44

def tests_to_run?
  @tests.any?
end

#tests_to_run_countObject


48
49
50
# File 'lib/assert/suite.rb', line 48

def tests_to_run_count
  @tests.size
end