anodator 0.0.5 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +5 -13
  6. data/LICENSE.txt +18 -17
  7. data/{README.ja.rdoc → README.ja.md} +2 -4
  8. data/README.md +39 -0
  9. data/Rakefile +3 -47
  10. data/anodator.gemspec +21 -103
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/anodator/check_result.rb +1 -1
  14. data/lib/anodator/input_spec.rb +2 -2
  15. data/lib/anodator/rule.rb +2 -2
  16. data/lib/anodator/utils.rb +4 -4
  17. data/lib/anodator/validator/format_validator.rb +1 -1
  18. data/lib/anodator/version.rb +3 -0
  19. data/lib/anodator.rb +1 -2
  20. metadata +70 -131
  21. data/Gemfile.lock +0 -29
  22. data/README.rdoc +0 -41
  23. data/spec/anodator/check_result_spec.rb +0 -101
  24. data/spec/anodator/checker_spec.rb +0 -273
  25. data/spec/anodator/input_spec_item_spec.rb +0 -100
  26. data/spec/anodator/input_spec_spec.rb +0 -584
  27. data/spec/anodator/message_spec.rb +0 -112
  28. data/spec/anodator/output_spec_spec.rb +0 -355
  29. data/spec/anodator/rule_set_spec.rb +0 -190
  30. data/spec/anodator/rule_spec.rb +0 -278
  31. data/spec/anodator/utils_spec.rb +0 -48
  32. data/spec/anodator/validator/base_spec.rb +0 -214
  33. data/spec/anodator/validator/blank_validator_spec.rb +0 -52
  34. data/spec/anodator/validator/complex_validator_spec.rb +0 -268
  35. data/spec/anodator/validator/date_validator_spec.rb +0 -350
  36. data/spec/anodator/validator/format_validator_spec.rb +0 -158
  37. data/spec/anodator/validator/inclusion_validator_spec.rb +0 -77
  38. data/spec/anodator/validator/length_validator_spec.rb +0 -236
  39. data/spec/anodator/validator/numeric_validator_spec.rb +0 -538
  40. data/spec/anodator/validator/presence_validator_spec.rb +0 -52
  41. data/spec/anodator/validator_spec.rb +0 -16
  42. data/spec/anodator_spec.rb +0 -2
  43. data/spec/spec_helper.rb +0 -12
@@ -1,538 +0,0 @@
1
- require "spec_helper"
2
-
3
- # Anodator::Validator::NumericValidator
4
- require "anodator/validator/numeric_validator"
5
-
6
- include Anodator::Validator
7
-
8
- describe NumericValidator, ".new" do
9
- context "with no parameters" do
10
- it "should raise ArgumentError" do
11
- lambda {
12
- NumericValidator.new
13
- }.should raise_error ArgumentError
14
- end
15
- end
16
-
17
- context "with only target expression" do
18
- before(:each) do
19
- @new_proc = lambda {
20
- NumericValidator.new("1")
21
- }
22
- end
23
-
24
- it "should not raise error" do
25
- @new_proc.should_not raise_error
26
- end
27
-
28
- it ":only_integer option must be false by default option" do
29
- @new_proc.call.options[:only_integer].should == false
30
- end
31
- end
32
-
33
- context "with target expression and :only_integer" do
34
- before(:each) do
35
- @new_proc = lambda {
36
- NumericValidator.new("1", :only_integer => true)
37
- }
38
- end
39
-
40
- it "should not raise error" do
41
- @new_proc.should_not raise_error
42
- end
43
-
44
- it ":only_integer option must be exists" do
45
- @new_proc.call.options[:only_integer].should == true
46
- end
47
- end
48
-
49
- context "with target expression and :greater_than" do
50
- before(:each) do
51
- @new_proc = lambda {
52
- NumericValidator.new("1", :greater_than => 10)
53
- }
54
- end
55
-
56
- it "should not raise error" do
57
- @new_proc.should_not raise_error
58
- end
59
-
60
- it ":greater_than option must be exists" do
61
- @new_proc.call.options[:greater_than].value.should == 10
62
- end
63
- end
64
-
65
- context "with target expression and :greater_than_or_equal_to" do
66
- before(:each) do
67
- @new_proc = lambda {
68
- NumericValidator.new("1", :greater_than_or_equal_to => 10)
69
- }
70
- end
71
-
72
- it "should not raise error" do
73
- @new_proc.should_not raise_error
74
- end
75
-
76
- it ":greater_than_or_equal_to option must be exists" do
77
- @new_proc.call.options[:greater_than_or_equal_to].value.should == 10
78
- end
79
- end
80
-
81
- context "with target expression and :less_than" do
82
- before(:each) do
83
- @new_proc = lambda {
84
- NumericValidator.new("1", :less_than => 10)
85
- }
86
- end
87
-
88
- it "should not raise error" do
89
- @new_proc.should_not raise_error
90
- end
91
-
92
- it ":less_than option must be exists" do
93
- @new_proc.call.options[:less_than].value.should == 10
94
- end
95
- end
96
-
97
- context "with target expression and :less_than_or_equal_to" do
98
- before(:each) do
99
- @new_proc = lambda {
100
- NumericValidator.new("1", :less_than_or_equal_to => 10)
101
- }
102
- end
103
-
104
- it "should not raise error" do
105
- @new_proc.should_not raise_error
106
- end
107
-
108
- it ":less_than_or_equal_to option must be exists" do
109
- @new_proc.call.options[:less_than_or_equal_to].value.should == 10
110
- end
111
- end
112
-
113
- context "with target expression and :equal_to" do
114
- before(:each) do
115
- @new_proc = lambda {
116
- NumericValidator.new("1", :equal_to => 10)
117
- }
118
- end
119
-
120
- it "should not raise error" do
121
- @new_proc.should_not raise_error
122
- end
123
-
124
- it ":equal_to option must be exists" do
125
- @new_proc.call.options[:equal_to].value.should == 10
126
- end
127
- end
128
-
129
- context "with target expression and :not_equal_to" do
130
- before(:each) do
131
- @new_proc = lambda {
132
- NumericValidator.new("1", :not_equal_to => 10)
133
- }
134
- end
135
-
136
- it "should not raise error" do
137
- @new_proc.should_not raise_error
138
- end
139
-
140
- it ":not_equal_to option must be exists" do
141
- @new_proc.call.options[:not_equal_to].value.should == 10
142
- end
143
- end
144
- end
145
-
146
- describe NumericValidator, "#valid?" do
147
- context "with only target expression" do
148
- before(:each) do
149
- @validator = NumericValidator.new("1")
150
- end
151
-
152
- context "values for valid integer" do
153
- before(:each) do
154
- Base.values = { "1" => "132" }
155
- end
156
-
157
- it { @validator.should be_valid }
158
- end
159
-
160
- context "values for valid floating point value" do
161
- before(:each) do
162
- Base.values = { "1" => "132.42" }
163
- end
164
-
165
- it { @validator.should be_valid }
166
- end
167
-
168
- context "values for invalid character" do
169
- before(:each) do
170
- Base.values = { "1" => "abdcd" }
171
- end
172
-
173
- it { @validator.should_not be_valid }
174
- end
175
-
176
- context "values for invalid number include alphabet" do
177
- before(:each) do
178
- Base.values = { "1" => "124.43fsd" }
179
- end
180
-
181
- it { @validator.should_not be_valid }
182
- end
183
-
184
- context "values for valid negative integer" do
185
- before(:each) do
186
- Base.values = { "1" => "-312" }
187
- end
188
-
189
- it { @validator.should be_valid }
190
- end
191
-
192
- context "values for valid negative floating point value" do
193
- before(:each) do
194
- Base.values = { "1" => "-13.442" }
195
- end
196
-
197
- it { @validator.should be_valid }
198
- end
199
- end
200
-
201
- context "with target expression and :only_integer" do
202
- before(:each) do
203
- @validator = NumericValidator.new("1", :only_integer => true)
204
- end
205
-
206
- context "values for valid integer" do
207
- before(:each) do
208
- Base.values = { "1" => "3252" }
209
- end
210
-
211
- it { @validator.should be_valid }
212
- end
213
-
214
- context "values for invalid floating point vlaue" do
215
- before(:each) do
216
- Base.values = { "1" => "42.43" }
217
- end
218
-
219
- it { @validator.should_not be_valid }
220
- end
221
- end
222
-
223
- context "with target expression and :greater_than" do
224
- before(:each) do
225
- @validator = NumericValidator.new("1", :greater_than => 10)
226
- end
227
-
228
- context "values for valid minimum value" do
229
- before(:each) do
230
- Base.values = { "1" => "11" }
231
- end
232
-
233
- it { @validator.should be_valid }
234
- end
235
-
236
- context "values for valid floating point value" do
237
- before(:each) do
238
- Base.values = { "1" => "10.00001" }
239
- end
240
-
241
- it { @validator.should be_valid }
242
- end
243
-
244
- context "values for invalid equal value" do
245
- before(:each) do
246
- Base.values = { "1" => "10" }
247
- end
248
-
249
- it { @validator.should_not be_valid }
250
- end
251
-
252
- context "values for invalid maximum value" do
253
- before(:each) do
254
- Base.values = { "1" => "9" }
255
- end
256
-
257
- it { @validator.should_not be_valid }
258
- end
259
-
260
- context "values for invalid maximum floating potin value" do
261
- before(:each) do
262
- Base.values = { "1" => "9.999999" }
263
- end
264
-
265
- it { @validator.should_not be_valid }
266
- end
267
- end
268
-
269
- context "with target expression and :greater_than_or_equal_to" do
270
- before(:each) do
271
- @validator = NumericValidator.new("1", :greater_than_or_equal_to => 10)
272
- end
273
-
274
- context "values for valid minimum value" do
275
- before(:each) do
276
- Base.values = { "1" => "11" }
277
- end
278
-
279
- it { @validator.should be_valid }
280
- end
281
-
282
- context "values for valid floating point value" do
283
- before(:each) do
284
- Base.values = { "1" => "10.0001" }
285
- end
286
-
287
- it { @validator.should be_valid }
288
- end
289
-
290
- context "values for valid equal value" do
291
- before(:each) do
292
- Base.values = { "1" => "10" }
293
- end
294
-
295
- it { @validator.should be_valid }
296
- end
297
-
298
- context "values for valid equal floating point value" do
299
- before(:each) do
300
- Base.values = { "1" => "10.0" }
301
- end
302
-
303
- it { @validator.should be_valid }
304
- end
305
-
306
- context "values for invalid maximum value" do
307
- before(:each) do
308
- Base.values = { "1" => "9" }
309
- end
310
-
311
- it { @validator.should_not be_valid }
312
- end
313
-
314
- context "values for invalid maximum floating potin value" do
315
- before(:each) do
316
- Base.values = { "1" => "9.999999" }
317
- end
318
-
319
- it { @validator.should_not be_valid }
320
- end
321
- end
322
-
323
- context "with target expression and :less_than" do
324
- before(:each) do
325
- @validator = NumericValidator.new("1", :less_than => 10)
326
- end
327
-
328
- context "values for valid maximum value" do
329
- before(:each) do
330
- Base.values = { "1" => "9" }
331
- end
332
-
333
- it { @validator.should be_valid }
334
- end
335
-
336
- context "values for valid maximum floating point value" do
337
- before(:each) do
338
- Base.values = { "1" => "9.9999999" }
339
- end
340
-
341
- it { @validator.should be_valid }
342
- end
343
-
344
- context "values for invalid equal value" do
345
- before(:each) do
346
- Base.values = { "1" => "10" }
347
- end
348
-
349
- it { @validator.should_not be_valid }
350
- end
351
-
352
- context "values for invalid equal floating point value" do
353
- before(:each) do
354
- Base.values = { "1" => "10.0" }
355
- end
356
-
357
- it { @validator.should_not be_valid }
358
- end
359
-
360
- context "values for invalid minimum value" do
361
- before(:each) do
362
- Base.values = { "1" => "11" }
363
- end
364
-
365
- it { @validator.should_not be_valid }
366
- end
367
-
368
- context "values for invalid minimum floating potin value" do
369
- before(:each) do
370
- Base.values = { "1" => "10.0000001" }
371
- end
372
-
373
- it { @validator.should_not be_valid }
374
- end
375
- end
376
-
377
- context "with target expression and :less_than_or_equal_to" do
378
- before(:each) do
379
- @validator = NumericValidator.new("1", :less_than_or_equal_to => 10)
380
- end
381
-
382
- context "values for valid maximum value" do
383
- before(:each) do
384
- Base.values = { "1" => "9" }
385
- end
386
-
387
- it { @validator.should be_valid }
388
- end
389
-
390
- context "values for valid maximum floating point value" do
391
- before(:each) do
392
- Base.values = { "1" => "9.9999999" }
393
- end
394
-
395
- it { @validator.should be_valid }
396
- end
397
-
398
- context "values for valid equal value" do
399
- before(:each) do
400
- Base.values = { "1" => "10" }
401
- end
402
-
403
- it { @validator.should be_valid }
404
- end
405
-
406
- context "values for valid equal floating point value" do
407
- before(:each) do
408
- Base.values = { "1" => "10.0" }
409
- end
410
-
411
- it { @validator.should be_valid }
412
- end
413
-
414
- context "values for invalid minimum value" do
415
- before(:each) do
416
- Base.values = { "1" => "11" }
417
- end
418
-
419
- it { @validator.should_not be_valid }
420
- end
421
-
422
- context "values for invalid minimum floating potin value" do
423
- before(:each) do
424
- Base.values = { "1" => "10.0000001" }
425
- end
426
-
427
- it { @validator.should_not be_valid }
428
- end
429
- end
430
-
431
- context "with target expression and :equal_to" do
432
- before(:each) do
433
- @validator = NumericValidator.new("1", :equal_to => 10)
434
- end
435
-
436
- context "values for invalid maximum value" do
437
- before(:each) do
438
- Base.values = { "1" => "9" }
439
- end
440
-
441
- it { @validator.should_not be_valid }
442
- end
443
-
444
- context "values for invalid maximum floating point value" do
445
- before(:each) do
446
- Base.values = { "1" => "9.9999999" }
447
- end
448
-
449
- it { @validator.should_not be_valid }
450
- end
451
-
452
- context "values for valid equal value" do
453
- before(:each) do
454
- Base.values = { "1" => "10" }
455
- end
456
-
457
- it { @validator.should be_valid }
458
- end
459
-
460
- context "values for valid equal floating point value" do
461
- before(:each) do
462
- Base.values = { "1" => "10.0" }
463
- end
464
-
465
- it { @validator.should be_valid }
466
- end
467
-
468
- context "values for invalid minimum value" do
469
- before(:each) do
470
- Base.values = { "1" => "11" }
471
- end
472
-
473
- it { @validator.should_not be_valid }
474
- end
475
-
476
- context "values for invalid minimum floating potin value" do
477
- before(:each) do
478
- Base.values = { "1" => "10.0000001" }
479
- end
480
-
481
- it { @validator.should_not be_valid }
482
- end
483
- end
484
-
485
- context "with target expression and :not_equal_to" do
486
- before(:each) do
487
- @validator = NumericValidator.new("1", :not_equal_to => 10)
488
- end
489
-
490
- context "values for valid maximum value" do
491
- before(:each) do
492
- Base.values = { "1" => "9" }
493
- end
494
-
495
- it { @validator.should be_valid }
496
- end
497
-
498
- context "values for valid maximum floating point value" do
499
- before(:each) do
500
- Base.values = { "1" => "9.9999999" }
501
- end
502
-
503
- it { @validator.should be_valid }
504
- end
505
-
506
- context "values for invalid equal value" do
507
- before(:each) do
508
- Base.values = { "1" => "10" }
509
- end
510
-
511
- it { @validator.should_not be_valid }
512
- end
513
-
514
- context "values for invalid equal floating point value" do
515
- before(:each) do
516
- Base.values = { "1" => "10.0" }
517
- end
518
-
519
- it { @validator.should_not be_valid }
520
- end
521
-
522
- context "values for valid minimum value" do
523
- before(:each) do
524
- Base.values = { "1" => "11" }
525
- end
526
-
527
- it { @validator.should be_valid }
528
- end
529
-
530
- context "values for valid minimum floating potin value" do
531
- before(:each) do
532
- Base.values = { "1" => "10.0000001" }
533
- end
534
-
535
- it { @validator.should be_valid }
536
- end
537
- end
538
- end
@@ -1,52 +0,0 @@
1
- require "spec_helper"
2
-
3
- # Anodator::Validator::PresenceValidator
4
- require "anodator/validator/presence_validator"
5
-
6
- describe Anodator::Validator::PresenceValidator, ".new" do
7
- context "with no parameters" do
8
- it "should raise ArgumentError" do
9
- lambda {
10
- Anodator::Validator::PresenceValidator.new
11
- }.should raise_error ArgumentError
12
- end
13
- end
14
-
15
- context "with only target parameter" do
16
- it "should not raise error" do
17
- lambda {
18
- Anodator::Validator::PresenceValidator.new("1")
19
- }.should_not raise_error
20
- end
21
- end
22
- end
23
-
24
- describe Anodator::Validator::PresenceValidator, "#valid?" do
25
- before(:each) do
26
- @validator = Anodator::Validator::PresenceValidator.new("1")
27
- end
28
-
29
- context "target value is blank" do
30
- before(:each) do
31
- Anodator::Validator::Base.values = { "1" => "" }
32
- end
33
-
34
- it { @validator.should_not be_valid }
35
- end
36
-
37
- context "target value is '1'" do
38
- before(:each) do
39
- Anodator::Validator::Base.values = { "1" => "1" }
40
- end
41
-
42
- it { @validator.should be_valid }
43
- end
44
-
45
- context "target value is 'some message'" do
46
- before(:each) do
47
- Anodator::Validator::Base.values = { "1" => "some message" }
48
- end
49
-
50
- it { @validator.should be_valid }
51
- end
52
- end
@@ -1,16 +0,0 @@
1
- require "spec_helper"
2
-
3
- # Anodator::Validator
4
- require "anodator/validator"
5
-
6
- describe "require validators" do
7
- it { Anodator::Validator::Base.should_not be_nil }
8
- it { Anodator::Validator::BlankValidator.should_not be_nil }
9
- it { Anodator::Validator::ComplexValidator.should_not be_nil }
10
- it { Anodator::Validator::FormatValidator.should_not be_nil }
11
- it { Anodator::Validator::InclusionValidator.should_not be_nil }
12
- it { Anodator::Validator::LengthValidator.should_not be_nil }
13
- it { Anodator::Validator::NumericValidator.should_not be_nil }
14
- it { Anodator::Validator::PresenceValidator.should_not be_nil }
15
- end
16
-
@@ -1,2 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
data/spec/spec_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'anodator'
5
-
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
-
12
- end