dtest 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+
2
+ require 'dtest/dsl'
3
+ require 'dtest/runner'
4
+ include DTest
5
+
6
+ describe Global::Manager, 'test assert' do
7
+
8
+ before do
9
+ $call = []
10
+ end
11
+
12
+ after do
13
+ Global::Manager.instance.clear
14
+ Test::Manager.instance.clear
15
+ end
16
+
17
+ it "assert global before" do
18
+ GlobalHarness do
19
+ before do
20
+ assert_equal(1,2)
21
+ end
22
+
23
+ after do
24
+ end
25
+ end
26
+
27
+ TestCase "test" do
28
+ test "empty" do
29
+ end
30
+ end
31
+
32
+ global_report = Runner.run([])
33
+ global_report.before_failure.failure.size.should == 1
34
+ global_report.after_failure.failure.size.should == 0
35
+ end
36
+
37
+ it "assert global after" do
38
+ GlobalHarness do
39
+ before do
40
+ end
41
+
42
+ after do
43
+ assert_equal(1 ,2)
44
+ end
45
+ end
46
+ TestCase "test" do
47
+ test "empty" do
48
+ end
49
+ end
50
+ global_report = Runner.run([])
51
+ global_report.before_failure.failure.size.should == 0
52
+ global_report.after_failure.failure.size.should == 1
53
+ end
54
+
55
+ it "assert testcase before/after" do
56
+ GlobalHarness do
57
+ end
58
+ TestCase "test" do
59
+ beforeCase do
60
+ assert_equal(1, 2)
61
+ end
62
+ afterCase do
63
+ assert_equal(1, 2)
64
+ end
65
+ end
66
+ global_report = Runner.run([])
67
+ global_report.result.size.should == 1
68
+ global_report.result.first.before_failure.failure.size.should == 1
69
+ global_report.result.first.after_failure.failure.size.should == 1
70
+ end
71
+
72
+
73
+ it "simple assert test" do
74
+ GlobalHarness do
75
+ end
76
+
77
+ TestCase "test" do
78
+ test "assert_equal" do
79
+ $call << :assert_equal
80
+ assert_equal(1, 1)
81
+ $call << :assert_equal
82
+ assert_equal(1, 2)
83
+ $call << :assert_equal_not_executed
84
+ end
85
+
86
+ test "assert_not_equal" do
87
+ $call << :assert_not_equal
88
+ assert_not_equal(1, 2)
89
+ $call << :assert_not_equal
90
+ assert_not_equal(1, 1)
91
+ $call << :assert_equal_not_executed
92
+ end
93
+
94
+ test "assert_true" do
95
+ $call << :assert_true
96
+ assert_true(true)
97
+ $call << :assert_true
98
+ assert_true(false)
99
+ $call << :assert_true_not_executed
100
+ end
101
+
102
+ test "assert_false" do
103
+ $call << :assert_false
104
+ assert_false(false)
105
+ $call << :assert_false
106
+ assert_false(true)
107
+ $call << :assert_not_true_not_executed
108
+ end
109
+
110
+
111
+ test "assert GlobalAbort", :assert_abort => :global do
112
+ $call << :assert_abort
113
+ assert_equal(1, 100)
114
+ $call << :not_executed
115
+ end
116
+ end
117
+
118
+ TestCase "not executed" do
119
+ test "not executed" do
120
+ $call << :not_executed
121
+ end
122
+ end
123
+
124
+ call = [
125
+ :assert_equal,
126
+ :assert_equal,
127
+
128
+ :assert_not_equal,
129
+ :assert_not_equal,
130
+
131
+ :assert_true,
132
+ :assert_true,
133
+
134
+ :assert_false,
135
+ :assert_false,
136
+
137
+ :assert_abort,
138
+ ]
139
+
140
+ global_report = Runner.run([])
141
+ $call.should == call
142
+ end
143
+
144
+
145
+ end
146
+
@@ -0,0 +1,303 @@
1
+ require 'dtest/dsl'
2
+ require 'dtest/runner'
3
+ include DTest
4
+
5
+ describe Global::Manager, 'global before/after exception' do
6
+ before do
7
+ $call = []
8
+ end
9
+
10
+ after do
11
+ Global::Manager.instance.clear
12
+ Test::Manager.instance.clear
13
+ end
14
+
15
+ it "global_before" do
16
+
17
+ GlobalHarness do
18
+ before do
19
+ $call << :before
20
+ raise Exception.new("test_global_before")
21
+ $call << :not_executed
22
+ end
23
+ after do
24
+ $call << :after
25
+ end
26
+ end
27
+
28
+ Runner.run([])
29
+ $call.should == [:before, :after]
30
+ end
31
+
32
+ it "global_after" do
33
+ GlobalHarness do
34
+ before do
35
+ $call << :before
36
+ end
37
+ after do
38
+ $call << :after
39
+ raise Exception.new("test_global_after")
40
+ $call << :not_executed
41
+ end
42
+ end
43
+
44
+ Runner.run([])
45
+ $call.should == [:before, :after]
46
+ end
47
+ end
48
+
49
+
50
+ describe Global::Manager, 'test before/after exception' do
51
+ before do
52
+ $call = []
53
+ GlobalHarness do
54
+ before do
55
+ $call << :beforeGlobal
56
+ end
57
+ after do
58
+ $call << :afterGlobal
59
+ end
60
+ end
61
+ end
62
+
63
+ after do
64
+ Global::Manager.instance.clear
65
+ Test::Manager.instance.clear
66
+ end
67
+
68
+ it "testcase:beforeCase" do
69
+ TestCase "testcase1" do
70
+ beforeCase do
71
+ $call << :beforeCase
72
+ raise Exception.new("test_beforeCase")
73
+ $call << :not_executed
74
+ end
75
+
76
+ afterCase do
77
+ $call << :afterCase
78
+ end
79
+
80
+ test "test1" do
81
+ $call << :test_not_executed # not_executed
82
+ end
83
+ end
84
+
85
+ Runner.run([])
86
+ $call.should == [
87
+ :beforeGlobal,
88
+ :beforeCase,
89
+ :afterCase,
90
+ :afterGlobal
91
+ ]
92
+ end
93
+
94
+ it "testcase:afterCase" do
95
+ TestCase "testcase1" do
96
+ beforeCase do
97
+ $call << :beforeCase
98
+ end
99
+
100
+ afterCase do
101
+ $call << :afterCase
102
+ raise Exception.new("test_afterCase")
103
+ $call << :not_executed
104
+ end
105
+
106
+ test "test1" do
107
+ $call << :test
108
+ end
109
+ end
110
+
111
+ Runner.run([])
112
+ $call.should == [
113
+ :beforeGlobal,
114
+ :beforeCase,
115
+ :test,
116
+ :afterCase,
117
+ :afterGlobal
118
+ ]
119
+ end
120
+
121
+ it "test:after" do
122
+ TestCase "after" do
123
+ before do
124
+ $call << :beforeCase
125
+ end
126
+
127
+ after do
128
+ $call << :afterCase
129
+ raise Exception.new("test_after")
130
+ $call << :not_executed
131
+ end
132
+
133
+ test "test1" do
134
+ $call << :test
135
+ end
136
+ end
137
+
138
+ Runner.run([])
139
+ $call.should == [
140
+ :beforeGlobal,
141
+ :beforeCase,
142
+ :test,
143
+ :afterCase,
144
+ :afterGlobal
145
+ ]
146
+ end
147
+
148
+ it "test:before" do
149
+ TestCase "after" do
150
+ before do
151
+ $call << :before
152
+ raise Exception.new("test_before")
153
+ $call << :not_executed
154
+ end
155
+
156
+ after do
157
+ $call << :after
158
+ end
159
+
160
+ test "test1" do
161
+ $call << :test_not_executed # not_executed
162
+ end
163
+ end
164
+
165
+ Runner.run([])
166
+ $call.should == [
167
+ :beforeGlobal,
168
+ :before,
169
+ :after,
170
+ :afterGlobal
171
+ ]
172
+ end
173
+
174
+ end
175
+
176
+
177
+
178
+ describe Global::Manager, 'exception catch' do
179
+ before do
180
+ $call = []
181
+
182
+ GlobalHarness do
183
+ before do
184
+ $call << :beforeGlobal
185
+ end
186
+ after do
187
+ $call << :afterGlobal
188
+ end
189
+ end
190
+ end
191
+
192
+ after do
193
+ Global::Manager.instance.clear
194
+ Test::Manager.instance.clear
195
+ end
196
+
197
+ it "exception caught" do
198
+ TestCase "exception_test" do
199
+ test "test1" do
200
+ assert_error(IOError) do
201
+ test = nil
202
+ tes += "" # NoMethodError
203
+ end
204
+ end
205
+ end
206
+
207
+ Runner.run([])
208
+ $call.should == [
209
+ :beforeGlobal,
210
+ :afterGlobal
211
+ ]
212
+
213
+ end
214
+
215
+ it "exception none was thrown" do
216
+
217
+ TestCase "exception_none" do
218
+ test "test1" do
219
+ assert_error(Exception) do
220
+ end
221
+ end
222
+ end
223
+
224
+ Runner.run([])
225
+ $call.should == [
226
+ :beforeGlobal,
227
+ :afterGlobal
228
+ ]
229
+
230
+ end
231
+
232
+ it "abort test" do
233
+ TestCase "testcase1" do
234
+ test "test1" do
235
+ $call << :test1
236
+ raise Exception.new("test1(assert_abort => :testcase)")
237
+ $call << :not_executed
238
+ end
239
+
240
+ test "test2" do
241
+ $call << :test2
242
+ end
243
+ end
244
+
245
+ Runner.run([])
246
+ $call.should == [
247
+ :beforeGlobal,
248
+ :test1,
249
+ :test2,
250
+ :afterGlobal
251
+ ]
252
+ end
253
+
254
+ it "abort testcase" do
255
+ TestCase "testcase1" do
256
+ test "test1", :assert_abort => :testcase do
257
+ $call << :test1
258
+ raise Exception.new("test1(assert_abort => :testcase)")
259
+ end
260
+
261
+ test "test2" do
262
+ $call << :test2_not_executed
263
+ end
264
+ end
265
+
266
+ Runner.run([])
267
+ $call.should == [
268
+ :beforeGlobal,
269
+ :test1,
270
+ :afterGlobal
271
+ ]
272
+ end
273
+
274
+ it "abort global" do
275
+ TestCase "testcase1" do
276
+ test "test1", :assert_abort => :global do
277
+ $call << :test1
278
+ raise Exception.new("test1(assert_abort => :global)")
279
+ end
280
+
281
+ test "test2" do
282
+ $call << :test2_not_executed
283
+ end
284
+ end
285
+
286
+ TestCase "testcase2" do
287
+ test "test1" do
288
+ $call << :test1_not_executed
289
+ end
290
+ end
291
+
292
+ Runner.run([])
293
+ $call.should == [
294
+ :beforeGlobal,
295
+ :test1,
296
+ :afterGlobal
297
+ ]
298
+ end
299
+
300
+ end
301
+
302
+
303
+
@@ -0,0 +1,288 @@
1
+ require 'dtest/dsl'
2
+ require 'dtest/runner'
3
+ include DTest
4
+
5
+
6
+ describe Global::Manager, 'execpted' do
7
+ before do
8
+ $call = []
9
+ end
10
+
11
+ after do
12
+ Global::Manager.instance.clear
13
+ Test::Manager.instance.clear
14
+ end
15
+
16
+ it "test expect_true" do
17
+ GlobalHarness do
18
+ before do
19
+ expect_true(false)
20
+ $call << :beforeGlobal
21
+ end
22
+
23
+ after do
24
+ expect_true(false)
25
+ $call << :afterGlobal
26
+ end
27
+ end
28
+
29
+ TestCase "expect_true" do
30
+ beforeCase do
31
+ expect_true(false)
32
+ $call << :beforeCase
33
+ end
34
+
35
+ afterCase do
36
+ expect_true(false)
37
+ $call << :afterCase
38
+ end
39
+
40
+ before do
41
+ expect_true(false)
42
+ $call << :before
43
+ end
44
+
45
+ after do
46
+ expect_true(false)
47
+ $call << :after
48
+ end
49
+
50
+ test "test1" do
51
+ expect_true(false)
52
+ $call << :test1
53
+ expect_true(false)
54
+ $call << :test2
55
+ end
56
+ end
57
+
58
+ call = [
59
+ :beforeGlobal,
60
+ :beforeCase,
61
+ :before,
62
+ :test1,
63
+ :test2,
64
+ :after,
65
+ :afterCase,
66
+ :afterGlobal,
67
+ ]
68
+
69
+
70
+ Runner.run([])
71
+ $call.should == call
72
+ end
73
+
74
+ it "test expect_equal" do
75
+ GlobalHarness do
76
+ before do
77
+ expect_equal(true, false)
78
+ $call << :beforeGlobal
79
+ end
80
+
81
+ after do
82
+ expect_equal(true, false)
83
+ $call << :afterGlobal
84
+ end
85
+ end
86
+
87
+ TestCase "expect_equal" do
88
+ beforeCase do
89
+ expect_equal(true, false)
90
+ $call << :beforeCase
91
+ end
92
+
93
+ afterCase do
94
+ expect_equal(true, false)
95
+ $call << :afterCase
96
+ end
97
+
98
+ before do
99
+ expect_equal(true, false)
100
+ $call << :before
101
+ end
102
+
103
+ after do
104
+ expect_equal(true, false)
105
+ $call << :after
106
+ end
107
+
108
+ test "test1" do
109
+ expect_equal(true, false)
110
+ $call << :test1
111
+ expect_equal(true, false)
112
+ $call << :test2
113
+ end
114
+ end
115
+
116
+ call = [
117
+ :beforeGlobal,
118
+ :beforeCase,
119
+ :before,
120
+ :test1,
121
+ :test2,
122
+ :after,
123
+ :afterCase,
124
+ :afterGlobal,
125
+ ]
126
+
127
+ Runner.run([])
128
+ $call.should == call
129
+ end
130
+
131
+ it "simple expect test" do
132
+
133
+ TestCase "test" do
134
+ before do
135
+ end
136
+
137
+ after do
138
+ end
139
+
140
+ test "expect_equal" do
141
+ $call << :expect_equal
142
+ expect_equal(1, 1)
143
+ $call << :expect_equal
144
+ expect_equal(1, 2)
145
+ $call << :expect_equal
146
+ end
147
+
148
+ test "expect_not_equal" do
149
+ $call << :expect_not_equal
150
+ expect_not_equal(1, 2)
151
+ $call << :expect_not_equal
152
+ expect_not_equal(1, 1)
153
+ $call << :expect_not_equal
154
+ end
155
+
156
+ test "expect_true" do
157
+ $call << :expect_true
158
+ expect_true(true)
159
+ $call << :expect_true
160
+ expect_true(false)
161
+ $call << :expect_true
162
+ end
163
+
164
+ test "expect_false" do
165
+ $call << :expect_false
166
+ expect_false(false)
167
+ $call << :expect_false
168
+ expect_false(true)
169
+ $call << :expect_false
170
+ end
171
+
172
+ end
173
+
174
+ TestCase "testcase2" do
175
+ test "test2" do
176
+ $call << :test
177
+ end
178
+ end
179
+
180
+ call = [
181
+ :expect_equal,
182
+ :expect_equal,
183
+ :expect_equal,
184
+
185
+ :expect_not_equal,
186
+ :expect_not_equal,
187
+ :expect_not_equal,
188
+
189
+ :expect_true,
190
+ :expect_true,
191
+ :expect_true,
192
+
193
+ :expect_false,
194
+ :expect_false,
195
+ :expect_false,
196
+
197
+ :test,
198
+ ]
199
+
200
+ global_report = Runner.run([])
201
+ $call.should == call
202
+ end
203
+ end
204
+
205
+
206
+
207
+ describe Global::Manager, 'expect failure count' do
208
+ before do
209
+ GlobalHarness do
210
+ before do
211
+ end
212
+
213
+ after do
214
+ end
215
+ end
216
+ end
217
+
218
+ after do
219
+ Global::Manager.instance.clear
220
+ Test::Manager.instance.clear
221
+ end
222
+
223
+ it "fail_before" do
224
+ TestCase "before" do
225
+ before do
226
+ expect_true(false)
227
+ end
228
+
229
+ after do
230
+ end
231
+
232
+ test "test" do
233
+ end
234
+
235
+ test "test" do
236
+ end
237
+ end
238
+ global = Runner.run([])
239
+ global.result.size.should == 1
240
+ result = global.result[0].result
241
+ result.size.should == 2
242
+ result[0].before_failure.failure.size.should == 1
243
+ result[1].before_failure.failure.size.should == 1
244
+ global.passed.should == 0
245
+ global.failed.should == 2
246
+ end
247
+
248
+ it "fail_after" do
249
+ TestCase "after" do
250
+ before do
251
+ end
252
+
253
+ after do
254
+ expect_true(false)
255
+ end
256
+
257
+ test "test" do
258
+ end
259
+ test "test" do
260
+ end
261
+ end
262
+ global = Runner.run([])
263
+ global.passed.should == 0
264
+ global.failed.should == 2
265
+ end
266
+
267
+ it "fail_test" do
268
+ TestCase "after" do
269
+ before do
270
+ end
271
+
272
+ after do
273
+ end
274
+
275
+ test "test" do
276
+ expect_true(false)
277
+ end
278
+
279
+ test "test" do
280
+ expect_true(true)
281
+ end
282
+ end
283
+ global = Runner.run([])
284
+ global.passed.should == 1
285
+ global.failed.should == 1
286
+ end
287
+ end
288
+