oktest 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +443 -35
- data/Rakefile.rb +5 -2
- data/benchmark/Rakefile.rb +4 -0
- data/lib/oktest.rb +549 -72
- data/oktest.gemspec +3 -3
- data/test/assertion_test.rb +70 -5
- data/test/filter_test.rb +2 -2
- data/test/fixture_test.rb +14 -1
- data/test/generator_test.rb +1 -1
- data/test/helper_test.rb +3 -3
- data/test/initialize.rb +8 -1
- data/test/mainapp_test.rb +95 -42
- data/test/matcher_test.rb +424 -0
- data/test/misc_test.rb +5 -5
- data/test/node_test.rb +27 -4
- data/test/reporter_test.rb +56 -29
- data/test/runner_test.rb +97 -25
- data/test/tc.rb +12 -0
- data/test/util_test.rb +71 -1
- data/test/utilhelper_test.rb +84 -0
- data/test/visitor_test.rb +1 -1
- metadata +9 -8
@@ -0,0 +1,424 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### $Release: 1.2.0 $
|
5
|
+
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
|
+
### $License: MIT License $
|
7
|
+
###
|
8
|
+
|
9
|
+
require_relative './initialize'
|
10
|
+
require 'set'
|
11
|
+
|
12
|
+
|
13
|
+
class Matcher_TC < TC
|
14
|
+
|
15
|
+
describe '#===' do
|
16
|
+
it "[!spybn] raises NotImplementedError." do
|
17
|
+
errmsg = "Oktest::Matcher#===(): not implemented yet."
|
18
|
+
assert_exc(NotImplementedError, errmsg) do
|
19
|
+
Oktest::Matcher.new(nil) === nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#==' do
|
25
|
+
it "[!ymt1b] raises OktestError." do
|
26
|
+
errmsg = "JSON(): use `===` instead of `==`."
|
27
|
+
assert_exc(Oktest::OktestError, errmsg) do
|
28
|
+
Oktest::Matcher.new(nil) == nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#fail()' do
|
34
|
+
it "[!8qpsd] raises assertion error." do
|
35
|
+
errmsg = "<<errmsg>>"
|
36
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
37
|
+
Oktest::Matcher.new(nil).fail("<<errmsg>>")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class JsonMatcher_TC < TC
|
46
|
+
|
47
|
+
def JSON(x)
|
48
|
+
return Oktest::JsonMatcher.new(x)
|
49
|
+
end
|
50
|
+
|
51
|
+
def OR(*args)
|
52
|
+
return Oktest::JsonMatcher::OR.new(*args)
|
53
|
+
end
|
54
|
+
|
55
|
+
def AND(*args)
|
56
|
+
return Oktest::JsonMatcher::AND.new(*args)
|
57
|
+
end
|
58
|
+
|
59
|
+
def ANY()
|
60
|
+
return Oktest::JsonMatcher::Any.new
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#===' do
|
64
|
+
it "[!4uf1o] raises assertion error when JSON not matched." do
|
65
|
+
assert_exc(Oktest::FAIL_EXCEPTION) do
|
66
|
+
JSON({"status": "ok"}) === {"status": "OK"}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
it "[!0g0u4] returns true when JSON matched." do
|
70
|
+
result = JSON({"status": "ok"}) === {"status": "ok"}
|
71
|
+
assert_eq result, true
|
72
|
+
end
|
73
|
+
it "[!1ukbv] scalar value matches to integer, string, bool, and so son." do
|
74
|
+
actual = {"name": "Alice", "age": 20, "deleted": false}
|
75
|
+
result = JSON(actual) === {"name": "Alice", "age": 20, "deleted": false}
|
76
|
+
assert_eq result, true
|
77
|
+
#
|
78
|
+
errmsg = ("$<JSON>[\"name\"]: $<expected> === $<actual> : failed.\n"\
|
79
|
+
" $<actual>: \"Alice\"\n"\
|
80
|
+
" $<expected>: \"alice\"\n")
|
81
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
82
|
+
JSON(actual) === {"name": "alice", "age": 20, "deleted": false}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it "[!8o55d] class object matches to instance object." do
|
86
|
+
actual = {"name": "Alice", "age": 20, "deleted": false}
|
87
|
+
result = JSON(actual) === {"name": String, "age": Integer, "deleted": FalseClass}
|
88
|
+
assert_eq result, true
|
89
|
+
#
|
90
|
+
errmsg = ("$<JSON>[\"deleted\"]: $<expected> === $<actual> : failed.\n"\
|
91
|
+
" $<actual>: false\n"\
|
92
|
+
" $<expected>: TrueClass\n")
|
93
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
94
|
+
JSON(actual) === {"name": String, "age": Integer, "deleted": TrueClass}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
it "[!s625d] regexp object matches to string value." do
|
98
|
+
actual = {"email": "alice@example.com"}
|
99
|
+
result = JSON(actual) === {"email": /^\w[-.\w]+@example\.(com|net|org)$/}
|
100
|
+
assert_eq result, true
|
101
|
+
#
|
102
|
+
errmsg = ("$<JSON>[\"email\"]: $<expected> === $<actual> : failed.\n"\
|
103
|
+
" $<actual>: \"alice@example.com\"\n"\
|
104
|
+
" $<expected>: /^\\w[-.\\w]+@example\\.org$/\n")
|
105
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
106
|
+
JSON(actual) === {"email": /^\w[-.\w]+@example\.org$/}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
it "[!aqkk0] range object matches to scalar value." do
|
110
|
+
actual = {"int": 5, "float": 3.14, "str": "abc"}
|
111
|
+
result = JSON(actual) === {"int": 1..10, "float": 3.1..3.2, "str": "aaa".."zzz"}
|
112
|
+
assert_eq result, true
|
113
|
+
#
|
114
|
+
errmsg = ("$<JSON>[\"int\"]: $<expected> === $<actual> : failed.\n"\
|
115
|
+
" $<actual>: 5\n"\
|
116
|
+
" $<expected>: 1...5\n")
|
117
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
118
|
+
JSON(actual) === {"int": 1...5, "float": 3.1..3.2, "str": "aaa".."zzz"}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
it "[!4ymj2] fails when actual value is not matched to item class of range object." do
|
122
|
+
actual = {"val": 1.5}
|
123
|
+
errmsg = ("$<JSON>[\"val\"]: expected #{1.class.name} value, but got Float value.\n"\
|
124
|
+
" $<actual>: 1.5\n"\
|
125
|
+
" $<expected>: 1..10\n")
|
126
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
127
|
+
JSON(actual) === {"val": 1..10}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
it "[!a7bfs] Set object matches to enum value." do
|
131
|
+
actual = {"gender": "female"}
|
132
|
+
result = JSON(actual) === {"gender": Set.new(["male", "female"])}
|
133
|
+
assert_eq result, true
|
134
|
+
#
|
135
|
+
errmsg = ("$<JSON>[\"gender\"]: $<expected> === $<actual> : failed.\n"\
|
136
|
+
" $<actual>: \"female\"\n"\
|
137
|
+
" $<expected>: #<Set: {\"M\", \"F\"}>\n")
|
138
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
139
|
+
JSON(actual) === {"gender": Set.new(["M", "F"])}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
it "[!sh5cg] Enumerator object matches to repeat of rule." do
|
143
|
+
actual = {"tags": ["foo", "bar", "baz"]}
|
144
|
+
result = JSON(actual) === {"tags": [String].each}
|
145
|
+
assert_eq result, true
|
146
|
+
#
|
147
|
+
errmsg = ("$<JSON>[\"tags\"][0]: $<expected> === $<actual> : failed.\n"\
|
148
|
+
" $<actual>: \"foo\"\n"\
|
149
|
+
" $<expected>: Integer\n")
|
150
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
151
|
+
JSON(actual) === {"tags": [Integer].each}
|
152
|
+
end
|
153
|
+
end
|
154
|
+
it "[!ljrmc] fails when expected is an Enumerator object and actual is not an array." do
|
155
|
+
actual = {"tags": "foo"}
|
156
|
+
errmsg = ("$<JSON>[\"tags\"]: Array value expected but got String value.\n"\
|
157
|
+
" $<actual>: \"foo\"\n"\
|
158
|
+
" $<expected>: [String].each\n")
|
159
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
160
|
+
JSON(actual) === {"tags": [String].each}
|
161
|
+
end
|
162
|
+
end
|
163
|
+
it "[!lh6d6] compares array items recursively." do
|
164
|
+
actual = {"items": [{"name": "Alice", "id": 101}, {"name": "Bob"}]}
|
165
|
+
result = JSON(actual) === {
|
166
|
+
"items": [{"name": String, "id?": 100..999}].each
|
167
|
+
}
|
168
|
+
assert_eq result, true
|
169
|
+
#
|
170
|
+
errmsg = ("$<JSON>[\"items\"][0][\"id\"]: $<expected> === $<actual> : failed.\n"\
|
171
|
+
" $<actual>: 101\n"\
|
172
|
+
" $<expected>: 1000..9999\n")
|
173
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
174
|
+
JSON(actual) === {
|
175
|
+
"items": [{"name": String, "id?": 1000..9999}].each
|
176
|
+
}
|
177
|
+
end
|
178
|
+
end
|
179
|
+
it "[!bz74w] fails when array lengths are different." do
|
180
|
+
actual = {"arr": ["A", "B", "C"]}
|
181
|
+
errmsg = ("$<JSON>[\"arr\"]: $<actual>.length == $<expected>.length : failed.\n"\
|
182
|
+
" $<actual>.length: 3\n"\
|
183
|
+
" $<expected>.length: 4\n"\
|
184
|
+
" $<actual>: [\"A\", \"B\", \"C\"]\n"\
|
185
|
+
" $<expected>: [\"A\", \"B\", \"C\", \"D\"]\n")
|
186
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
187
|
+
JSON(actual) === {"arr": ["A", "B", "C", "D"]}
|
188
|
+
end
|
189
|
+
end
|
190
|
+
it "[!fmxyg] compares hash objects recursively." do
|
191
|
+
actual = {
|
192
|
+
"owner": {"name": "Alice", "age": 20},
|
193
|
+
"item": {"id": 10001, "name": "Something", "price": 500},
|
194
|
+
}
|
195
|
+
result = JSON(actual) === {
|
196
|
+
"owner": {"name": String, "age": 0..100},
|
197
|
+
"item": {"id": 1..99999, "name": String, "price?": Numeric},
|
198
|
+
}
|
199
|
+
assert_eq result, true
|
200
|
+
#
|
201
|
+
errmsg = ("$<JSON>[\"item\"][\"price\"]: $<expected> === $<actual> : failed.\n"\
|
202
|
+
" $<actual>: 500\n"\
|
203
|
+
" $<expected>: Float\n")
|
204
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
205
|
+
JSON(actual) === {
|
206
|
+
"owner": {"name": String, "age": 0..100},
|
207
|
+
"item": {"id": 1..99999, "name": String, "price?": Float},
|
208
|
+
}
|
209
|
+
end
|
210
|
+
end
|
211
|
+
it "[!rkv0z] compares two hashes with converting keys into string." do
|
212
|
+
actual1 = {k1: "A", k2: "B"}
|
213
|
+
result = JSON(actual1) === {"k1"=>"A", "k2"=>"B"}
|
214
|
+
assert_eq result, true
|
215
|
+
#
|
216
|
+
actual2 = {"k1"=>"A", "k2"=>"B"}
|
217
|
+
result = JSON(actual2) === {k1: "A", k2: "B"}
|
218
|
+
assert_eq result, true
|
219
|
+
end
|
220
|
+
it "[!jbyv6] key 'aaa?' represents optional key." do
|
221
|
+
actual1 = {"name": "alice", "birth": "2000-01-01"}
|
222
|
+
result = JSON(actual1) === {"name": "alice", "birth?": "2000-01-01"}
|
223
|
+
assert_eq result, true
|
224
|
+
#
|
225
|
+
actual2 = {"name": "alice"}
|
226
|
+
result = JSON(actual2) === {"name": "alice", "birth?": "2000-01-01"}
|
227
|
+
assert_eq result, true
|
228
|
+
#
|
229
|
+
actual3 = {"name": "alice", "birth": nil}
|
230
|
+
result = JSON(actual3) === {"name": "alice", "birth?": "2000-01-01"}
|
231
|
+
assert_eq result, true
|
232
|
+
#
|
233
|
+
actual4 = {"name": "alice", "birth?": "2000-01-01"} # TODO
|
234
|
+
result = JSON(actual4) === {"name": "alice", "birth?": "2000-01-01"}
|
235
|
+
assert_eq result, true
|
236
|
+
end
|
237
|
+
it "[!mpbvu] fails when unexpected key exists in actual hash." do
|
238
|
+
actual = {"id": 101, "name": "Alice"}
|
239
|
+
errmsg = ("$<JSON>: key \"gender\" expected but not found.\n"\
|
240
|
+
" $<actual>.keys: \"id\", \"name\"\n"\
|
241
|
+
" $<expected>.keys: \"gender\", \"id\", \"name\"\n")
|
242
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
243
|
+
JSON(actual) === {"id": Integer, "name": String, "gender": String}
|
244
|
+
end
|
245
|
+
end
|
246
|
+
it "[!4oasq] fails when expected key not exist in actual hash." do
|
247
|
+
actual = {"id": 101, "name": "Alice"}
|
248
|
+
errmsg = ("$<JSON>[\"id\"]: unexpected key.\n"\
|
249
|
+
" $<actual>: 101\n")
|
250
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
251
|
+
JSON(actual) === {"name": String}
|
252
|
+
end
|
253
|
+
end
|
254
|
+
it "[!eqr3b] `OR()` matches to any of arguments." do
|
255
|
+
result = JSON({"val": 123}) === {"val": OR(String, Integer)}
|
256
|
+
assert_eq result, true
|
257
|
+
result = JSON({"val": "123"}) === {"val": OR(String, Integer)}
|
258
|
+
assert_eq result, true
|
259
|
+
#
|
260
|
+
errmsg = ("$<JSON>[\"val\"]: $<expected> === $<actual> : failed.\n"\
|
261
|
+
" $<actual>: 3.14\n"\
|
262
|
+
" $<expected>: OR(String, Integer)\n")
|
263
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
264
|
+
JSON({"val": 3.14}) === {"val": OR(String, Integer)}
|
265
|
+
end
|
266
|
+
end
|
267
|
+
it "[!4hk96] `AND()` matches to all of arguments." do
|
268
|
+
result = JSON({"val": "alice"}) === {"val": AND(String, /^[a-z]+$/)}
|
269
|
+
assert_eq result, true
|
270
|
+
#
|
271
|
+
errmsg = ("$<JSON>[\"val\"]: $<expected> === $<actual> : failed.\n"\
|
272
|
+
" $<actual>: \"Alice\"\n"\
|
273
|
+
" $<expected>: AND(/^[a-z]+$/)\n")
|
274
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
275
|
+
JSON({"val": "Alice"}) === {"val": AND(String, /^[a-z]+$/)}
|
276
|
+
end
|
277
|
+
end
|
278
|
+
it "[!5ybfg] `OR()` can contain `AND()`." do
|
279
|
+
expected = {"val": OR(AND(String, /^\d+$/), AND(Integer, 100..999))}
|
280
|
+
result = JSON({"val": "123"}) === expected
|
281
|
+
assert_eq result, true
|
282
|
+
result = JSON({"val": 123}) === expected
|
283
|
+
assert_eq result, true
|
284
|
+
#
|
285
|
+
errmsg = ("$<JSON>[\"val\"]: $<expected> === $<actual> : failed.\n"\
|
286
|
+
" $<actual>: \"abc\"\n"\
|
287
|
+
" $<expected>: OR(AND(String, /^\\d+$/), AND(Integer, 100..999))\n")
|
288
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
289
|
+
JSON({"val": "abc"}) === expected
|
290
|
+
end
|
291
|
+
errmsg = ("$<JSON>[\"val\"]: $<expected> === $<actual> : failed.\n"\
|
292
|
+
" $<actual>: 99\n"\
|
293
|
+
" $<expected>: OR(AND(String, /^\\d+$/), AND(Integer, 100..999))\n")
|
294
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
295
|
+
JSON({"val": 99}) === expected
|
296
|
+
end
|
297
|
+
end
|
298
|
+
it "[!scx22] `AND()` can contain `OR()`." do
|
299
|
+
expected = {"val": AND(OR(String, Integer), OR(/^\d{3}$/, 100..999))}
|
300
|
+
result = JSON({"val": "123"}) === expected
|
301
|
+
assert_eq result, true
|
302
|
+
result = JSON({"val": 123}) === expected
|
303
|
+
assert_eq result, true
|
304
|
+
#
|
305
|
+
errmsg = ("$<JSON>[\"val\"]: $<expected> === $<actual> : failed.\n"\
|
306
|
+
" $<actual>: \"1\"\n"\
|
307
|
+
" $<expected>: AND(OR(/^\\d{3}$/, 100..999))\n")
|
308
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
309
|
+
JSON({"val": "1"}) === expected
|
310
|
+
end
|
311
|
+
errmsg = ("$<JSON>[\"val\"]: $<expected> === $<actual> : failed.\n"\
|
312
|
+
" $<actual>: 0\n"\
|
313
|
+
" $<expected>: AND(OR(/^\\d{3}$/, 100..999))\n")
|
314
|
+
assert_exc(Oktest::FAIL_EXCEPTION, errmsg) do
|
315
|
+
JSON({"val": 0}) === expected
|
316
|
+
end
|
317
|
+
end
|
318
|
+
it "[!uc4ag] key '*' matches to any key name." do
|
319
|
+
actual = {"name": "Alice", "age": 20}
|
320
|
+
result = JSON(actual) === {"name": String, "*": Integer}
|
321
|
+
assert_eq result, true
|
322
|
+
result = JSON(actual) === {"name": String, "*": ANY()}
|
323
|
+
assert_eq result, true
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
describe '#_compare?()' do
|
328
|
+
it "[!nkvqo] returns true when nothing raised." do
|
329
|
+
result = JSON(nil).instance_eval { _compare?([], "abc", /^\w+$/) }
|
330
|
+
assert_eq result, true
|
331
|
+
end
|
332
|
+
it "[!57m2j] returns false when assertion error raised." do
|
333
|
+
result = JSON(nil).instance_eval { _compare?([], "abc", /^\d+$/) }
|
334
|
+
assert_eq result, false
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
class OR_TC < TC
|
342
|
+
|
343
|
+
describe '#inspect()' do
|
344
|
+
it "[!2mu33] returns 'OR(...)' string." do
|
345
|
+
o = Oktest::JsonMatcher::OR.new('A', 'B', 'C')
|
346
|
+
assert_eq o.inspect(), 'OR("A", "B", "C")'
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
|
353
|
+
class AND_TC < TC
|
354
|
+
|
355
|
+
describe '#inspect()' do
|
356
|
+
it "[!w43ag] returns 'AND(...)' string." do
|
357
|
+
o = Oktest::JsonMatcher::AND.new('A', 'B', 'C')
|
358
|
+
assert_eq o.inspect(), 'AND("A", "B", "C")'
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
|
365
|
+
class Enum_TC < TC
|
366
|
+
|
367
|
+
describe '#inspect()' do
|
368
|
+
it "[!fam11] returns 'Enum(...)' string." do
|
369
|
+
o = Oktest::JsonMatcher::Enum.new(['A', 'B', 'C'])
|
370
|
+
assert_eq o.inspect(), 'Enum("A", "B", "C")'
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
|
377
|
+
class Length_TC < TC
|
378
|
+
|
379
|
+
describe '#===' do
|
380
|
+
it "[!03ozi] compares length of actual value with expected value." do
|
381
|
+
o1 = Oktest::JsonMatcher::Length.new(3)
|
382
|
+
assert_eq (o1 === "abc"), true
|
383
|
+
assert_eq (o1 === "abcd"), false
|
384
|
+
assert_eq (o1 === [1,2,3]), true
|
385
|
+
assert_eq (o1 === [1, 2]), false
|
386
|
+
o2 = Oktest::JsonMatcher::Length.new(1..3)
|
387
|
+
assert_eq (o2 === "a"), true
|
388
|
+
assert_eq (o2 === "abc"), true
|
389
|
+
assert_eq (o2 === ""), false
|
390
|
+
assert_eq (o2 === "abcd"), false
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
describe '#inspect()' do
|
395
|
+
it "[!nwv3e] returns 'Length(n)' string." do
|
396
|
+
o = Oktest::JsonMatcher::Length.new(1..3)
|
397
|
+
assert_eq o.inspect, "Length(1..3)"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
|
404
|
+
class Any_TC < TC
|
405
|
+
|
406
|
+
describe '#===' do
|
407
|
+
it "[!mzion] returns true in any case." do
|
408
|
+
o = Oktest::JsonMatcher::Any.new()
|
409
|
+
assert_eq (o === nil) , true
|
410
|
+
assert_eq (o === true) , true
|
411
|
+
assert_eq (o === false), true
|
412
|
+
assert_eq (o === 123) , true
|
413
|
+
assert_eq (o === "abc"), true
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
describe '#inspect()' do
|
418
|
+
it "[!6f0yv] returns 'Any()' string." do
|
419
|
+
o = Oktest::JsonMatcher::Any.new()
|
420
|
+
assert_eq o.inspect, "Any()"
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
data/test/misc_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 1.0
|
4
|
+
### $Release: 1.2.0 $
|
5
5
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -69,11 +69,11 @@ class Color_TC < TC
|
|
69
69
|
|
70
70
|
describe '.status()' do
|
71
71
|
it "[!yev5y] returns string containing color escape sequence." do
|
72
|
-
assert_eq Oktest::Color.status(:PASS , "Pass" ), "\e[
|
73
|
-
assert_eq Oktest::Color.status(:FAIL , "Fail" ), "\e[
|
72
|
+
assert_eq Oktest::Color.status(:PASS , "Pass" ), "\e[0;36mPass\e[0m"
|
73
|
+
assert_eq Oktest::Color.status(:FAIL , "Fail" ), "\e[0;31mFail\e[0m"
|
74
74
|
assert_eq Oktest::Color.status(:ERROR, "Error"), "\e[1;31mError\e[0m"
|
75
|
-
assert_eq Oktest::Color.status(:SKIP , "Skip" ), "\e[
|
76
|
-
assert_eq Oktest::Color.status(:TODO , "Todo" ), "\e[
|
75
|
+
assert_eq Oktest::Color.status(:SKIP , "Skip" ), "\e[0;33mSkip\e[0m"
|
76
|
+
assert_eq Oktest::Color.status(:TODO , "Todo" ), "\e[0;33mTodo\e[0m"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/test/node_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 1.0
|
4
|
+
### $Release: 1.2.0 $
|
5
5
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -315,13 +315,25 @@ class ScopeFunctions_TC < TC
|
|
315
315
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
316
316
|
end
|
317
317
|
|
318
|
+
class DummyLocation # < Thread::Backtrace::Location
|
319
|
+
def initialize(string)
|
320
|
+
string =~ /([^:]+):(\d+)/
|
321
|
+
@path = $1
|
322
|
+
@lineno = $2
|
323
|
+
end
|
324
|
+
attr_reader :path, :lineno
|
325
|
+
end
|
326
|
+
|
318
327
|
def with_dummy_location(location)
|
319
328
|
$_dummy_location = location
|
320
329
|
Oktest.module_eval do
|
321
330
|
class << self
|
322
|
-
def caller(n)
|
331
|
+
def caller(n, len=nil)
|
323
332
|
return [$_dummy_location]
|
324
333
|
end
|
334
|
+
def caller_locations(n, len=nil)
|
335
|
+
return [DummyLocation.new($_dummy_location)]
|
336
|
+
end
|
325
337
|
end
|
326
338
|
end
|
327
339
|
yield
|
@@ -329,6 +341,7 @@ class ScopeFunctions_TC < TC
|
|
329
341
|
Oktest.module_eval do
|
330
342
|
class << self
|
331
343
|
remove_method :caller
|
344
|
+
remove_method :caller_locations
|
332
345
|
end
|
333
346
|
end
|
334
347
|
$_dummy_location = nil
|
@@ -533,6 +546,16 @@ class Context_TC < TC
|
|
533
546
|
assert_eq sp.tag, "exp"
|
534
547
|
assert_eq sp._prefix, "-"
|
535
548
|
end
|
549
|
+
it "[!4vkbl] error when `fixture:` keyword arg is not a Hash object." do
|
550
|
+
new_node_with() do
|
551
|
+
spec "example #2", fixture: {x: 1} do end # not raise anything
|
552
|
+
end
|
553
|
+
assert_exc(ArgumentError, 'spec(fixture: "x: 1"): fixture argument should be a Hash object, but got String object.') do
|
554
|
+
new_node_with() do
|
555
|
+
spec "example #2", fixture: "x: 1" do end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
536
559
|
it "[!ala78] provides raising TodoException block if block not given." do
|
537
560
|
node = new_node_with() do
|
538
561
|
spec "example #3"
|
@@ -552,7 +575,7 @@ class Context_TC < TC
|
|
552
575
|
sp1, sp2 = node.each_child.to_a
|
553
576
|
assert_eq sp1.location, nil
|
554
577
|
assert sp2.location != nil, "not nil"
|
555
|
-
assert sp2.location.start_with?("#{__FILE__}:#{lineno}:in")
|
578
|
+
assert sp2.location.to_s.start_with?("#{__FILE__}:#{lineno}:in")
|
556
579
|
end
|
557
580
|
end
|
558
581
|
|
@@ -568,7 +591,7 @@ class Context_TC < TC
|
|
568
591
|
assert node.fixtures.key?(:alice), "key not registerd"
|
569
592
|
assert node.fixtures[:alice][0].is_a?(Proc), "block expected"
|
570
593
|
assert_eq node.fixtures[:alice][1], nil
|
571
|
-
assert node.fixtures[:alice][2].start_with?("#{__FILE__}:#{lineno}:in ")
|
594
|
+
assert node.fixtures[:alice][2].to_s.start_with?("#{__FILE__}:#{lineno}:in ")
|
572
595
|
end
|
573
596
|
it "[!y3ks3] retrieves block parameter names." do
|
574
597
|
node = new_node_with() do
|