Class: Nitrous::Test
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Assertions
#assert!, #assert_equal!, #assert_match!, #assert_nil!, #assert_not_equal!, #assert_not_raised!, #assert_raise!, #fail, included, method_added
Constructor Details
#initialize(context) ⇒ Test
Returns a new instance of Test.
78
79
80
81
|
# File 'lib/nitrous/test.rb', line 78
def initialize(context)
@context = context
@test_results = []
end
|
Class Method Details
.callbacks ⇒ Object
10
11
12
|
# File 'lib/nitrous/test.rb', line 10
def self.callbacks
@@callbacks ||= {:suite_setup => [], :suite_teardown => [], :setup => [], :teardown => []}
end
|
.exclude(klass) ⇒ Object
47
48
49
|
# File 'lib/nitrous/test.rb', line 47
def self.exclude(klass)
@test_classes.delete(klass)
end
|
.inherited(subclass) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/nitrous/test.rb', line 51
def self.inherited(subclass)
class << subclass
def inherited(subclass)
Nitrous::Test.exclude(self)
Nitrous::Test.inherited(subclass)
end
end
if !@test_classes
@test_classes = []
at_exit do
callbacks[:suite_setup].each(&:call)
context = TestContext.create(@test_classes.sum {|klass| klass.tests.size})
@test_classes.each do |klass|
klass.run(context)
end
context.finish
callbacks[:suite_teardown].each(&:call)
exit(context.exit_status)
end
end
@test_classes << subclass
end
|
.register_callback(type, &callback) ⇒ Object
18
19
20
|
# File 'lib/nitrous/test.rb', line 18
def self.register_callback(type, &callback)
callbacks[type] << callback
end
|
.run(context = TestContext.new) ⇒ Object
74
75
76
|
# File 'lib/nitrous/test.rb', line 74
def self.run(context=TestContext.new)
self.new(context).run
end
|
.setup ⇒ Object
83
|
# File 'lib/nitrous/test.rb', line 83
def self.setup; end
|
.stest(name = nil, &block) ⇒ Object
38
39
40
41
|
# File 'lib/nitrous/test.rb', line 38
def self.stest(name=nil, &block)
@tests = [TestBlock.new(name, block)]
@single_test = true;
end
|
.teardown ⇒ Object
84
|
# File 'lib/nitrous/test.rb', line 84
def self.teardown; end
|
.test(name = nil, &block) ⇒ Object
34
35
36
|
# File 'lib/nitrous/test.rb', line 34
def self.test(name=nil, &block)
self.tests << TestBlock.new(name, block) unless @single_test
end
|
.test_classes ⇒ Object
30
31
32
|
# File 'lib/nitrous/test.rb', line 30
def self.test_classes
@test_classes ||= []
end
|
.tests ⇒ Object
26
27
28
|
# File 'lib/nitrous/test.rb', line 26
def self.tests
@tests ||= []
end
|
.ztest(name = nil, &block) ⇒ Object
43
44
45
|
# File 'lib/nitrous/test.rb', line 43
def self.ztest(name=nil, &block)
self.tests << TestBlock.new(name, block, true) unless @single_test
end
|
Instance Method Details
#callbacks ⇒ Object
14
15
16
|
# File 'lib/nitrous/test.rb', line 14
def callbacks
self.class.callbacks
end
|
#collect_errors ⇒ Object
90
91
92
93
94
95
|
# File 'lib/nitrous/test.rb', line 90
def collect_errors
yield
rescue Exception
@test_results.last.errors << $!
@context.failed($!)
end
|
#nitrous_setup ⇒ Object
85
|
# File 'lib/nitrous/test.rb', line 85
def nitrous_setup; end
|
#nitrous_teardown ⇒ Object
86
|
# File 'lib/nitrous/test.rb', line 86
def nitrous_teardown; end
|
#register_callback(type, &callback) ⇒ Object
22
23
24
|
# File 'lib/nitrous/test.rb', line 22
def register_callback(type, &callback)
self.class.register_callback(type, callback)
end
|
#run ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/nitrous/test.rb', line 102
def run
puts self.class.name
self.class.setup
self.class.tests.each do |test_block|
running(test_block)
nitrous_setup
collect_errors do
callbacks[:setup].each(&:call)
setup
test_block.run(self)
teardown
callbacks[:teardown].each(&:call)
end
nitrous_teardown
@context.ran_test(test_block, @test_results.last)
end
self.class.teardown
end
|
#running(test) ⇒ Object
97
98
99
100
|
# File 'lib/nitrous/test.rb', line 97
def running(test)
@current_test = test
@test_results << TestResult.new(test)
end
|
#setup ⇒ Object
87
|
# File 'lib/nitrous/test.rb', line 87
def setup; end
|
#teardown ⇒ Object
88
|
# File 'lib/nitrous/test.rb', line 88
def teardown; end
|