anodator 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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.ja.rdoc +33 -0
- data/README.rdoc +41 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/example/example_01.rb +129 -0
- data/lib/anodator/anodator_error.rb +5 -0
- data/lib/anodator/check_result.rb +41 -0
- data/lib/anodator/checker.rb +58 -0
- data/lib/anodator/input_spec.rb +199 -0
- data/lib/anodator/input_spec_item.rb +33 -0
- data/lib/anodator/message.rb +59 -0
- data/lib/anodator/output_spec.rb +164 -0
- data/lib/anodator/rule.rb +97 -0
- data/lib/anodator/rule_set.rb +52 -0
- data/lib/anodator/utils.rb +234 -0
- data/lib/anodator/validator/base.rb +168 -0
- data/lib/anodator/validator/blank_validator.rb +14 -0
- data/lib/anodator/validator/complex_validator.rb +60 -0
- data/lib/anodator/validator/configuration_error.rb +8 -0
- data/lib/anodator/validator/date_validator.rb +151 -0
- data/lib/anodator/validator/format_validator.rb +48 -0
- data/lib/anodator/validator/inclusion_validator.rb +21 -0
- data/lib/anodator/validator/length_validator.rb +37 -0
- data/lib/anodator/validator/numeric_validator.rb +46 -0
- data/lib/anodator/validator/presence_validator.rb +14 -0
- data/lib/anodator/validator.rb +10 -0
- data/lib/anodator.rb +3 -0
- data/spec/anodator/check_result_spec.rb +101 -0
- data/spec/anodator/checker_spec.rb +273 -0
- data/spec/anodator/input_spec_item_spec.rb +100 -0
- data/spec/anodator/input_spec_spec.rb +584 -0
- data/spec/anodator/message_spec.rb +112 -0
- data/spec/anodator/output_spec_spec.rb +355 -0
- data/spec/anodator/rule_set_spec.rb +190 -0
- data/spec/anodator/rule_spec.rb +169 -0
- data/spec/anodator/validator/base_spec.rb +214 -0
- data/spec/anodator/validator/blank_validator_spec.rb +52 -0
- data/spec/anodator/validator/complex_validator_spec.rb +268 -0
- data/spec/anodator/validator/date_validator_spec.rb +350 -0
- data/spec/anodator/validator/format_validator_spec.rb +158 -0
- data/spec/anodator/validator/inclusion_validator_spec.rb +77 -0
- data/spec/anodator/validator/length_validator_spec.rb +236 -0
- data/spec/anodator/validator/numeric_validator_spec.rb +468 -0
- data/spec/anodator/validator/presence_validator_spec.rb +52 -0
- data/spec/anodator/validator_spec.rb +16 -0
- data/spec/anodator_spec.rb +2 -0
- data/spec/spec_helper.rb +12 -0
- metadata +188 -0
@@ -0,0 +1,584 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Anodator::InputSpec
|
4
|
+
require "anodator/input_spec"
|
5
|
+
|
6
|
+
include Anodator
|
7
|
+
|
8
|
+
describe InputSpec, ".new" do
|
9
|
+
context "with no parameters" do
|
10
|
+
it "should not raise error" do
|
11
|
+
lambda {
|
12
|
+
InputSpec.new
|
13
|
+
}.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "@spec_items.count should be zero" do
|
17
|
+
input_spec = InputSpec.new
|
18
|
+
input_spec.instance_eval("@spec_items.count").should be_zero
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with several items parameter" do
|
23
|
+
before(:all) do
|
24
|
+
@new_proc = lambda {
|
25
|
+
InputSpec.new([
|
26
|
+
{ :number => "1", :name => "item_1" },
|
27
|
+
{ :number => "2", :name => "item_2" },
|
28
|
+
{ :number => "3", :name => "item_3" },
|
29
|
+
{ :number => "4", :name => "item_4" },
|
30
|
+
{ :number => "5", :name => "item_5", :type => InputSpecItem::TYPE_NUMERIC },
|
31
|
+
{ :number => "6", :name => "item_6" },
|
32
|
+
{ :number => "7", :name => "item_7" },
|
33
|
+
{ :number => "8", :name => "item_8" },
|
34
|
+
{ :number => "9", :name => "item_9" },
|
35
|
+
])
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not raise error" do
|
40
|
+
@new_proc.should_not raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it "@spec_items.count should be 9" do
|
44
|
+
input_spec = @new_proc.call
|
45
|
+
input_spec.instance_eval("@spec_items.count").should == 9
|
46
|
+
end
|
47
|
+
|
48
|
+
it "@spec_items.each type.should be STRING" do
|
49
|
+
input_spec = @new_proc.call
|
50
|
+
input_spec.instance_eval("@spec_items").each do |input_spec_item|
|
51
|
+
if input_spec_item.number == "5"
|
52
|
+
input_spec_item.type.should == InputSpecItem::TYPE_NUMERIC
|
53
|
+
else
|
54
|
+
input_spec_item.type.should == InputSpecItem::TYPE_STRING
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe InputSpec, "after generated" do
|
62
|
+
before(:each) do
|
63
|
+
@input_spec = InputSpec.new([
|
64
|
+
{ :number => "1", :name => "item_1" },
|
65
|
+
{ :number => "2", :name => "item_2" },
|
66
|
+
{ :number => "3", :name => "item_3" },
|
67
|
+
{ :number => "4", :name => "item_4" },
|
68
|
+
{ :number => "5", :name => "item_5", :type => InputSpecItem::TYPE_NUMERIC },
|
69
|
+
{ :number => "6", :name => "item_6", :type => InputSpecItem::TYPE_NUMERIC },
|
70
|
+
{ :number => "7", :name => "item_7" },
|
71
|
+
{ :number => "8", :name => "item_8" },
|
72
|
+
{ :number => "9", :name => "item_9" },
|
73
|
+
])
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#source=" do
|
77
|
+
context "with valid array values" do
|
78
|
+
before(:each) do
|
79
|
+
@values = %W(1 2 3 4 5 6 7 8 9)
|
80
|
+
@proc = lambda {
|
81
|
+
@input_spec.source = @values
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not raise error" do
|
86
|
+
@proc.should_not raise_error
|
87
|
+
end
|
88
|
+
|
89
|
+
it "@source should equal presented values" do
|
90
|
+
@proc.should change { @input_spec.instance_eval("@source") }.
|
91
|
+
from(nil).to(@values)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "with invalid fixnum value" do
|
96
|
+
it "should raise ArgumentError" do
|
97
|
+
lambda {
|
98
|
+
@input_spec.source = nil
|
99
|
+
}.should raise_error ArgumentError
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#clear_source" do
|
105
|
+
before(:each) do
|
106
|
+
@values = %W(1 2 3 4 5 6 7 8 9)
|
107
|
+
@input_spec.source = @values
|
108
|
+
@proc = lambda {
|
109
|
+
@input_spec.clear_source
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
it "@source should change to nil" do
|
114
|
+
@proc.should change { @input_spec.instance_eval("@source") }.
|
115
|
+
from(@values).to(nil)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#[]" do
|
120
|
+
context "when initialized source" do
|
121
|
+
before(:each) do
|
122
|
+
@values = %W(1 2 3 4 5 6 7 8 9)
|
123
|
+
@input_spec.source = @values
|
124
|
+
end
|
125
|
+
|
126
|
+
context "when access existing index" do
|
127
|
+
before(:each) do
|
128
|
+
@proc = lambda {
|
129
|
+
@input_spec[3]
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should get value" do
|
134
|
+
@proc.call.should == @values[3]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when access non-existing index" do
|
139
|
+
before(:each) do
|
140
|
+
@proc = lambda {
|
141
|
+
@input_spec[@values.size]
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should raise error UnknownTargetExpressionError" do
|
146
|
+
@proc.should raise_error UnknownTargetExpressionError
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when access existing number" do
|
151
|
+
before(:each) do
|
152
|
+
@proc = lambda {
|
153
|
+
@input_spec["7"]
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should get value" do
|
158
|
+
@proc.call.should == @values[6]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when access non-existing number" do
|
163
|
+
before(:each) do
|
164
|
+
@proc = lambda {
|
165
|
+
@input_spec[(@values.size + 1).to_s]
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should raise error UnknownTargetExpressionError" do
|
170
|
+
@proc.should raise_error UnknownTargetExpressionError
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "when access existing name" do
|
175
|
+
before(:each) do
|
176
|
+
@proc = lambda {
|
177
|
+
@input_spec["item_2"]
|
178
|
+
}
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should get value" do
|
182
|
+
@proc.call.should == @values[1]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "when access non-existing name" do
|
187
|
+
before(:each) do
|
188
|
+
@proc = lambda {
|
189
|
+
@input_spec["unknown"]
|
190
|
+
}
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should raise error UnknownTargetExpressionError" do
|
194
|
+
@proc.should raise_error UnknownTargetExpressionError
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when access valid calculation expression" do
|
199
|
+
before(:each) do
|
200
|
+
@proc = lambda {
|
201
|
+
@input_spec["CALC::[[1]]+[[2]]"]
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should not raise error" do
|
206
|
+
@proc.should_not raise_error
|
207
|
+
end
|
208
|
+
|
209
|
+
it { @proc.call.should == "12" }
|
210
|
+
end
|
211
|
+
|
212
|
+
context "when access invalid calculation expression with unknown number" do
|
213
|
+
before(:each) do
|
214
|
+
@proc = lambda {
|
215
|
+
@input_spec["CALC::[[1]]+[[12]]"]
|
216
|
+
}
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should raise UnknownTargetExpressionError" do
|
220
|
+
@proc.should raise_error UnknownTargetExpressionError
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "when access invalid calculation expression with syntax error" do
|
225
|
+
before(:each) do
|
226
|
+
@proc = lambda {
|
227
|
+
@input_spec["CALC::[[1]][[2]]"]
|
228
|
+
}
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should raise UnknownTargetExpressionError" do
|
232
|
+
@proc.should_not raise_error UnknownTargetExpressionError
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "when access valid calculation expression for numeric add" do
|
237
|
+
before(:each) do
|
238
|
+
@proc = lambda {
|
239
|
+
@input_spec["CALC::[[5]]+[[6]]"]
|
240
|
+
}
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should not raise error" do
|
244
|
+
@proc.should_not raise_error
|
245
|
+
end
|
246
|
+
|
247
|
+
it { @proc.call.should == "11.0" }
|
248
|
+
end
|
249
|
+
|
250
|
+
context "when access invalid calculation expression for numeric and string add" do
|
251
|
+
before(:each) do
|
252
|
+
@proc = lambda {
|
253
|
+
@input_spec["CALC::[[1]]+[[6]]"]
|
254
|
+
}
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should raise UnknownTargetExpressionError" do
|
258
|
+
@proc.should raise_error UnknownTargetExpressionError
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context "when not initialized source" do
|
264
|
+
it "should raise error" do
|
265
|
+
lambda {
|
266
|
+
@input_spec[0]
|
267
|
+
}.should raise_error SourceDataNotProvidedError
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe "#value_at" do
|
273
|
+
context "when initialized source" do
|
274
|
+
before(:each) do
|
275
|
+
@values = %W(1 2 3 4 5 6 7 8 9)
|
276
|
+
@input_spec.source = @values
|
277
|
+
end
|
278
|
+
|
279
|
+
context "when access existing index" do
|
280
|
+
before(:each) do
|
281
|
+
@proc = lambda {
|
282
|
+
@input_spec.value_at(3)
|
283
|
+
}
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should get value" do
|
287
|
+
@proc.call.should == @values[3]
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context "when access non-existing index" do
|
292
|
+
before(:each) do
|
293
|
+
@proc = lambda {
|
294
|
+
@input_spec.value_at(@values.size)
|
295
|
+
}
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should raise error UnknownTargetExpressionError" do
|
299
|
+
@proc.should raise_error UnknownTargetExpressionError
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "when not initialized source" do
|
305
|
+
it "should raise error" do
|
306
|
+
lambda {
|
307
|
+
@input_spec.value_at(0)
|
308
|
+
}.should raise_error SourceDataNotProvidedError
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe "#value_at_by_number" do
|
314
|
+
context "when initialized source" do
|
315
|
+
before(:each) do
|
316
|
+
@values = %W(1 2 3 4 5 6 7 8 9)
|
317
|
+
@input_spec.source = @values
|
318
|
+
end
|
319
|
+
|
320
|
+
context "when access existing number" do
|
321
|
+
before(:each) do
|
322
|
+
@proc = lambda {
|
323
|
+
@input_spec.value_at_by_number("7")
|
324
|
+
}
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should get value" do
|
328
|
+
@proc.call.should == @values[6]
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
context "when access non-existing number" do
|
333
|
+
before(:each) do
|
334
|
+
@proc = lambda {
|
335
|
+
@input_spec.value_at_by_number((@values.size + 1).to_s)
|
336
|
+
}
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should raise error UnknownTargetExpressionError" do
|
340
|
+
@proc.should raise_error UnknownTargetExpressionError
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
context "when not initialized source" do
|
346
|
+
it "should raise error" do
|
347
|
+
lambda {
|
348
|
+
@input_spec.value_at_by_number("0")
|
349
|
+
}.should raise_error SourceDataNotProvidedError
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
describe "#value_at_by_name" do
|
355
|
+
context "when initialized source" do
|
356
|
+
before(:each) do
|
357
|
+
@values = %W(1 2 3 4 5 6 7 8 9)
|
358
|
+
@input_spec.source = @values
|
359
|
+
end
|
360
|
+
|
361
|
+
context "when access existing name" do
|
362
|
+
before(:each) do
|
363
|
+
@proc = lambda {
|
364
|
+
@input_spec.value_at_by_name("item_2")
|
365
|
+
}
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should get value" do
|
369
|
+
@proc.call.should == @values[1]
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
context "when access non-existing name" do
|
374
|
+
before(:each) do
|
375
|
+
@proc = lambda {
|
376
|
+
@input_spec.value_at_by_name("unknown")
|
377
|
+
}
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should raise error UnknownTargetExpressionError" do
|
381
|
+
@proc.should raise_error UnknownTargetExpressionError
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
context "when not initialized source" do
|
387
|
+
it "should raise error" do
|
388
|
+
lambda {
|
389
|
+
@input_spec.value_at_by_name("item_3")
|
390
|
+
}.should raise_error SourceDataNotProvidedError
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe "#spec_item_by_expression" do
|
396
|
+
context "when access existing index" do
|
397
|
+
before(:each) do
|
398
|
+
@proc = lambda {
|
399
|
+
@input_spec.spec_item_by_expression(3)
|
400
|
+
}
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should get spec item" do
|
404
|
+
@proc.call.number.should == "4"
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
context "when access non-existing index" do
|
409
|
+
before(:each) do
|
410
|
+
@proc = lambda {
|
411
|
+
@input_spec.spec_item_by_expression(9)
|
412
|
+
}
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should raise error UnknownTargetExpressionError" do
|
416
|
+
@proc.should raise_error UnknownTargetExpressionError
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
context "when access existing number" do
|
421
|
+
before(:each) do
|
422
|
+
@proc = lambda {
|
423
|
+
@input_spec.spec_item_by_expression("7")
|
424
|
+
}
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should get spec item" do
|
428
|
+
@proc.call.number.should == "7"
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
context "when access non-existing number" do
|
433
|
+
before(:each) do
|
434
|
+
@proc = lambda {
|
435
|
+
@input_spec.spec_item_by_expression("10")
|
436
|
+
}
|
437
|
+
end
|
438
|
+
|
439
|
+
it "should raise error UnknownTargetExpressionError" do
|
440
|
+
@proc.should raise_error UnknownTargetExpressionError
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
context "when access existing name" do
|
445
|
+
before(:each) do
|
446
|
+
@proc = lambda {
|
447
|
+
@input_spec.spec_item_by_expression("item_2")
|
448
|
+
}
|
449
|
+
end
|
450
|
+
|
451
|
+
it "should get spec item" do
|
452
|
+
@proc.call.number.should == "2"
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
context "when access non-existing name" do
|
457
|
+
before(:each) do
|
458
|
+
@proc = lambda {
|
459
|
+
@input_spec.spec_item_by_expression("unknown")
|
460
|
+
}
|
461
|
+
end
|
462
|
+
|
463
|
+
it "should raise error UnknownTargetExpressionError" do
|
464
|
+
@proc.should raise_error UnknownTargetExpressionError
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
context "when access valid calculation expression" do
|
469
|
+
before(:each) do
|
470
|
+
@proc = lambda {
|
471
|
+
@input_spec.spec_item_by_expression("CALC::[[1]]+[[2]]")
|
472
|
+
}
|
473
|
+
end
|
474
|
+
|
475
|
+
it "should not raise error" do
|
476
|
+
@proc.should_not raise_error
|
477
|
+
end
|
478
|
+
|
479
|
+
it { @proc.call.should == [@input_spec.spec_item_at_by_number("1"),
|
480
|
+
@input_spec.spec_item_at_by_number("2")] }
|
481
|
+
end
|
482
|
+
|
483
|
+
context "when access invalid calculation expression with unknown number" do
|
484
|
+
before(:each) do
|
485
|
+
@proc = lambda {
|
486
|
+
@input_spec.spec_item_by_expression("CALC::[[1]]+[[12]]")
|
487
|
+
}
|
488
|
+
end
|
489
|
+
|
490
|
+
it "should raise UnknownTargetExpressionError" do
|
491
|
+
@proc.should raise_error UnknownTargetExpressionError
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
context "when access invalid calculation expression with syntax error" do
|
496
|
+
before(:each) do
|
497
|
+
@proc = lambda {
|
498
|
+
@input_spec.spec_item_by_expression("CALC::[[1]][[2]]")
|
499
|
+
}
|
500
|
+
end
|
501
|
+
|
502
|
+
it { @proc.call.should == [@input_spec.spec_item_at_by_number("1"),
|
503
|
+
@input_spec.spec_item_at_by_number("2")] }
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
describe "#spec_item_at" do
|
508
|
+
context "when access existing index" do
|
509
|
+
before(:each) do
|
510
|
+
@proc = lambda {
|
511
|
+
@input_spec.spec_item_at(3)
|
512
|
+
}
|
513
|
+
end
|
514
|
+
|
515
|
+
it "should get spec item" do
|
516
|
+
@proc.call.number.should == "4"
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
context "when access non-existing index" do
|
521
|
+
before(:each) do
|
522
|
+
@proc = lambda {
|
523
|
+
@input_spec.spec_item_at(9)
|
524
|
+
}
|
525
|
+
end
|
526
|
+
|
527
|
+
it "should raise error UnknownTargetExpressionError" do
|
528
|
+
@proc.should raise_error UnknownTargetExpressionError
|
529
|
+
end
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
describe "#spec_item_at_by_number" do
|
534
|
+
context "when access existing number" do
|
535
|
+
before(:each) do
|
536
|
+
@proc = lambda {
|
537
|
+
@input_spec.spec_item_at_by_number("7")
|
538
|
+
}
|
539
|
+
end
|
540
|
+
|
541
|
+
it "should get spec item" do
|
542
|
+
@proc.call.number.should == "7"
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
context "when access non-existing number" do
|
547
|
+
before(:each) do
|
548
|
+
@proc = lambda {
|
549
|
+
@input_spec.spec_item_at_by_number("10")
|
550
|
+
}
|
551
|
+
end
|
552
|
+
|
553
|
+
it "should raise error UnknownTargetExpressionError" do
|
554
|
+
@proc.should raise_error UnknownTargetExpressionError
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
describe "#spec_item_at_by_name" do
|
560
|
+
context "when access existing name" do
|
561
|
+
before(:each) do
|
562
|
+
@proc = lambda {
|
563
|
+
@input_spec.spec_item_at_by_name("item_2")
|
564
|
+
}
|
565
|
+
end
|
566
|
+
|
567
|
+
it "should get spec item" do
|
568
|
+
@proc.call.number.should == "2"
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
context "when access non-existing name" do
|
573
|
+
before(:each) do
|
574
|
+
@proc = lambda {
|
575
|
+
@input_spec.spec_item_at_by_name("unknown")
|
576
|
+
}
|
577
|
+
end
|
578
|
+
|
579
|
+
it "should raise error UnknownTargetExpressionError" do
|
580
|
+
@proc.should raise_error UnknownTargetExpressionError
|
581
|
+
end
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Anodator::Message
|
4
|
+
require "anodator/message"
|
5
|
+
require "anodator/input_spec"
|
6
|
+
|
7
|
+
include Anodator
|
8
|
+
|
9
|
+
describe Message, ".new" do
|
10
|
+
context "with no parameters" do
|
11
|
+
it "should raise ArgumentError" do
|
12
|
+
lambda {
|
13
|
+
Message.new
|
14
|
+
}.should raise_error ArgumentError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with simple template_message" do
|
19
|
+
before(:each) do
|
20
|
+
@new_proc = lambda {
|
21
|
+
Message.new("An error occured!!")
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not raise error" do
|
26
|
+
@new_proc.should_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#template should be provided string" do
|
30
|
+
@message = @new_proc.call
|
31
|
+
@message.template.should == "An error occured!!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with template_message include place holder" do
|
36
|
+
before(:each) do
|
37
|
+
@template = "An error occured [[1::name]]([[1::number]]) must not be [[1::value]]"
|
38
|
+
@new_proc = lambda {
|
39
|
+
Message.new(@template)
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not raise error" do
|
44
|
+
@new_proc.should_not raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "#template should be provided string" do
|
48
|
+
@message = @new_proc.call
|
49
|
+
@message.template.should == @template
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Message, "#expand" do
|
55
|
+
before(:each) do
|
56
|
+
# create input spec and data source
|
57
|
+
@input_spec = InputSpec.new([
|
58
|
+
{ :number => "1", :name => "item_1" },
|
59
|
+
{ :number => "2", :name => "item_2" },
|
60
|
+
{ :number => "3", :name => "item_3" },
|
61
|
+
{ :number => "4", :name => "item_4" },
|
62
|
+
{ :number => "5", :name => "item_5" },
|
63
|
+
])
|
64
|
+
@values = %W(1 2 3 4 5)
|
65
|
+
@input_spec.source = @values
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when message is valid" do
|
69
|
+
before(:each) do
|
70
|
+
@template = "An error occured [[1::name]]([[1::number]]) must not be '[[1::value]]'"
|
71
|
+
@message = Message.new(@template)
|
72
|
+
@proc = lambda { @message.expand(@input_spec) }
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not raise error" do
|
76
|
+
@proc.should_not raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should equal replacement values" do
|
80
|
+
@proc.call.should ==
|
81
|
+
"An error occured item_1(1) must not be '1'"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when message's place holder contain unknown field" do
|
86
|
+
context "include unknown target_expression" do
|
87
|
+
before(:each) do
|
88
|
+
@template = "An error occured [[1::name]]([[1::number]]) must not be [[289::value]]"
|
89
|
+
@message = Message.new(@template)
|
90
|
+
@proc = lambda { @message.expand(@input_spec) }
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should raise UnknownTargetExpressionError" do
|
94
|
+
@proc.should raise_error UnknownTargetExpressionError
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when message's place holder contain unknown field" do
|
100
|
+
context "include unknown attribute" do
|
101
|
+
before(:each) do
|
102
|
+
@template = "An error occured [[1::name]]([[1::number]]) must not be [[1::values]]"
|
103
|
+
@message = Message.new(@template)
|
104
|
+
@proc = lambda { @message.expand(@input_spec) }
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should raise UnknownMessageAttributeError" do
|
108
|
+
@proc.should raise_error UnknownMessageAttributeError
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|