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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -13
- data/LICENSE.txt +18 -17
- data/{README.ja.rdoc → README.ja.md} +2 -4
- data/README.md +39 -0
- data/Rakefile +3 -47
- data/anodator.gemspec +21 -103
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/anodator/check_result.rb +1 -1
- data/lib/anodator/input_spec.rb +2 -2
- data/lib/anodator/rule.rb +2 -2
- data/lib/anodator/utils.rb +4 -4
- data/lib/anodator/validator/format_validator.rb +1 -1
- data/lib/anodator/version.rb +3 -0
- data/lib/anodator.rb +1 -2
- metadata +70 -131
- data/Gemfile.lock +0 -29
- data/README.rdoc +0 -41
- data/spec/anodator/check_result_spec.rb +0 -101
- data/spec/anodator/checker_spec.rb +0 -273
- data/spec/anodator/input_spec_item_spec.rb +0 -100
- data/spec/anodator/input_spec_spec.rb +0 -584
- data/spec/anodator/message_spec.rb +0 -112
- data/spec/anodator/output_spec_spec.rb +0 -355
- data/spec/anodator/rule_set_spec.rb +0 -190
- data/spec/anodator/rule_spec.rb +0 -278
- data/spec/anodator/utils_spec.rb +0 -48
- data/spec/anodator/validator/base_spec.rb +0 -214
- data/spec/anodator/validator/blank_validator_spec.rb +0 -52
- data/spec/anodator/validator/complex_validator_spec.rb +0 -268
- data/spec/anodator/validator/date_validator_spec.rb +0 -350
- data/spec/anodator/validator/format_validator_spec.rb +0 -158
- data/spec/anodator/validator/inclusion_validator_spec.rb +0 -77
- data/spec/anodator/validator/length_validator_spec.rb +0 -236
- data/spec/anodator/validator/numeric_validator_spec.rb +0 -538
- data/spec/anodator/validator/presence_validator_spec.rb +0 -52
- data/spec/anodator/validator_spec.rb +0 -16
- data/spec/anodator_spec.rb +0 -2
- data/spec/spec_helper.rb +0 -12
metadata
CHANGED
@@ -1,111 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: anodator
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
version: 0.0.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre1
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Tetsuhisa MAKINO
|
13
8
|
autorequire:
|
14
|
-
bindir:
|
9
|
+
bindir: exe
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
-
requirements:
|
23
|
-
- - ~>
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
segments:
|
26
|
-
- 2
|
27
|
-
- 3
|
28
|
-
- 0
|
29
|
-
version: 2.3.0
|
30
|
-
prerelease: false
|
31
|
-
name: rspec
|
32
|
-
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ~>
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
segments:
|
40
|
-
- 1
|
41
|
-
- 0
|
42
|
-
- 0
|
43
|
-
version: 1.0.0
|
44
|
-
prerelease: false
|
11
|
+
date: 2017-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
45
14
|
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
46
20
|
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 1
|
55
|
-
- 6
|
56
|
-
- 4
|
57
|
-
version: 1.6.4
|
58
21
|
prerelease: false
|
59
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
60
34
|
type: :development
|
61
|
-
version_requirements: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
version: "0"
|
70
35
|
prerelease: false
|
71
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
72
48
|
type: :development
|
73
|
-
version_requirements: *id004
|
74
|
-
- !ruby/object:Gem::Dependency
|
75
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
76
|
-
requirements:
|
77
|
-
- - "="
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
- 8
|
82
|
-
- 7
|
83
|
-
version: 0.8.7
|
84
49
|
prerelease: false
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- tim.makino at gmail.com
|
90
58
|
executables: []
|
91
|
-
|
92
59
|
extensions: []
|
93
|
-
|
94
|
-
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
|
99
|
-
- .document
|
100
|
-
- .rspec
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".document"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
101
66
|
- Gemfile
|
102
|
-
- Gemfile.lock
|
103
67
|
- LICENSE.txt
|
104
|
-
- README.ja.
|
105
|
-
- README.
|
68
|
+
- README.ja.md
|
69
|
+
- README.md
|
106
70
|
- Rakefile
|
107
71
|
- VERSION
|
108
72
|
- anodator.gemspec
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
109
75
|
- example/example_01.rb
|
110
76
|
- lib/anodator.rb
|
111
77
|
- lib/anodator/anodator_error.rb
|
@@ -130,56 +96,29 @@ files:
|
|
130
96
|
- lib/anodator/validator/numeric_validator.rb
|
131
97
|
- lib/anodator/validator/presence_validator.rb
|
132
98
|
- lib/anodator/validator/value_proxy.rb
|
133
|
-
-
|
134
|
-
- spec/anodator/checker_spec.rb
|
135
|
-
- spec/anodator/input_spec_item_spec.rb
|
136
|
-
- spec/anodator/input_spec_spec.rb
|
137
|
-
- spec/anodator/message_spec.rb
|
138
|
-
- spec/anodator/output_spec_spec.rb
|
139
|
-
- spec/anodator/rule_set_spec.rb
|
140
|
-
- spec/anodator/rule_spec.rb
|
141
|
-
- spec/anodator/utils_spec.rb
|
142
|
-
- spec/anodator/validator/base_spec.rb
|
143
|
-
- spec/anodator/validator/blank_validator_spec.rb
|
144
|
-
- spec/anodator/validator/complex_validator_spec.rb
|
145
|
-
- spec/anodator/validator/date_validator_spec.rb
|
146
|
-
- spec/anodator/validator/format_validator_spec.rb
|
147
|
-
- spec/anodator/validator/inclusion_validator_spec.rb
|
148
|
-
- spec/anodator/validator/length_validator_spec.rb
|
149
|
-
- spec/anodator/validator/numeric_validator_spec.rb
|
150
|
-
- spec/anodator/validator/presence_validator_spec.rb
|
151
|
-
- spec/anodator/validator_spec.rb
|
152
|
-
- spec/anodator_spec.rb
|
153
|
-
- spec/spec_helper.rb
|
154
|
-
has_rdoc: true
|
99
|
+
- lib/anodator/version.rb
|
155
100
|
homepage: https://github.com/maki-tetsu/anodator
|
156
|
-
licenses:
|
101
|
+
licenses:
|
157
102
|
- MIT
|
103
|
+
metadata: {}
|
158
104
|
post_install_message:
|
159
105
|
rdoc_options: []
|
160
|
-
|
161
|
-
require_paths:
|
106
|
+
require_paths:
|
162
107
|
- lib
|
163
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
-
requirements:
|
165
|
-
- - ">="
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
segments:
|
168
|
-
- 0
|
169
|
-
version: "0"
|
170
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
-
requirements:
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
172
110
|
- - ">="
|
173
|
-
- !ruby/object:Gem::Version
|
174
|
-
|
175
|
-
|
176
|
-
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.1
|
177
118
|
requirements: []
|
178
|
-
|
179
119
|
rubyforge_project:
|
180
|
-
rubygems_version:
|
120
|
+
rubygems_version: 2.6.13
|
181
121
|
signing_key:
|
182
|
-
specification_version:
|
122
|
+
specification_version: 4
|
183
123
|
summary: anodator is Anonymous Data Validator.
|
184
124
|
test_files: []
|
185
|
-
|
data/Gemfile.lock
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
diff-lcs (1.1.2)
|
5
|
-
git (1.2.5)
|
6
|
-
jeweler (1.6.4)
|
7
|
-
bundler (~> 1.0)
|
8
|
-
git (>= 1.2.5)
|
9
|
-
rake
|
10
|
-
rake (0.8.7)
|
11
|
-
rcov (0.9.9)
|
12
|
-
rspec (2.3.0)
|
13
|
-
rspec-core (~> 2.3.0)
|
14
|
-
rspec-expectations (~> 2.3.0)
|
15
|
-
rspec-mocks (~> 2.3.0)
|
16
|
-
rspec-core (2.3.1)
|
17
|
-
rspec-expectations (2.3.0)
|
18
|
-
diff-lcs (~> 1.1.2)
|
19
|
-
rspec-mocks (2.3.0)
|
20
|
-
|
21
|
-
PLATFORMS
|
22
|
-
ruby
|
23
|
-
|
24
|
-
DEPENDENCIES
|
25
|
-
bundler (~> 1.0.0)
|
26
|
-
jeweler (~> 1.6.4)
|
27
|
-
rake (= 0.8.7)
|
28
|
-
rcov
|
29
|
-
rspec (~> 2.3.0)
|
data/README.rdoc
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
= anodator is Anonymous Data Validator
|
2
|
-
|
3
|
-
anodator is a library to help you check the text data. Text data being checked
|
4
|
-
is passed in an array, The output will be printed as two-dimensional array.
|
5
|
-
anodator is checked upon the specifications of the received data, a set of rules
|
6
|
-
for checking, And by receiving the output specification, corresponds to the
|
7
|
-
input of any type. Although usually performed on the various specifications such
|
8
|
-
as Ruby code and passing, how a simple set Will be provided.
|
9
|
-
|
10
|
-
== How to install
|
11
|
-
|
12
|
-
Please run the following command from the command line.
|
13
|
-
|
14
|
-
$ gem install anodator
|
15
|
-
|
16
|
-
== To use a library
|
17
|
-
|
18
|
-
(Written later)
|
19
|
-
|
20
|
-
== To use a command
|
21
|
-
|
22
|
-
(Written later)
|
23
|
-
|
24
|
-
== Contributing to anodator
|
25
|
-
|
26
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
27
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
28
|
-
* Fork the project
|
29
|
-
* Start a feature/bugfix branch
|
30
|
-
* Commit and push until you are happy with your contribution
|
31
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
32
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
33
|
-
|
34
|
-
== Author
|
35
|
-
|
36
|
-
Tetsuhisa MAKINO <tim.makino at gmail.com>
|
37
|
-
|
38
|
-
== Copyright
|
39
|
-
|
40
|
-
Copyright (c) 2011 Tetsuhisa MAKINO. See LICENSE.txt for
|
41
|
-
further details.
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::CheckResult
|
4
|
-
require "anodator/check_result"
|
5
|
-
|
6
|
-
include Anodator
|
7
|
-
|
8
|
-
describe CheckResult, ".new" do
|
9
|
-
context "with no parameters" do
|
10
|
-
it "should raise error ArgumentError" do
|
11
|
-
lambda {
|
12
|
-
CheckResult.new
|
13
|
-
}.should raise_error ArgumentError
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "with only target_numbers" do
|
18
|
-
it "should raise error ArgumentError" do
|
19
|
-
lambda {
|
20
|
-
CheckResult.new(["1", "2"])
|
21
|
-
}.should raise_error ArgumentError
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with target_numbers and message" do
|
26
|
-
before(:each) do
|
27
|
-
@new_proc = lambda {
|
28
|
-
CheckResult.new(["1", "2"], "An error occured for 1 and 2 values.")
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should raise ArgumentError" do
|
33
|
-
@new_proc.should raise_error ArgumentError
|
34
|
-
end
|
35
|
-
end
|
36
|
-
context "with target_numbers, message and level" do
|
37
|
-
before(:each) do
|
38
|
-
@new_proc = lambda {
|
39
|
-
CheckResult.new(["1", "2"], "An error occured for 1 and 2 values.", Rule::ERROR_LEVELS[:error])
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should not raise error" do
|
44
|
-
@new_proc.should_not raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
context "after generated" do
|
48
|
-
before(:each) do
|
49
|
-
@check_result = @new_proc.call
|
50
|
-
end
|
51
|
-
|
52
|
-
it "#target_numbers should be set" do
|
53
|
-
@check_result.target_numbers.should == ["1", "2"]
|
54
|
-
end
|
55
|
-
|
56
|
-
it "#message should be set" do
|
57
|
-
@check_result.message.should == "An error occured for 1 and 2 values."
|
58
|
-
end
|
59
|
-
|
60
|
-
it "#level should be set" do
|
61
|
-
@check_result.level.should == Rule::ERROR_LEVELS[:error]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe CheckResult, "#error?" do
|
68
|
-
context "when level is error" do
|
69
|
-
before(:each) do
|
70
|
-
@check_result = CheckResult.new("1", "message", Rule::ERROR_LEVELS[:error])
|
71
|
-
end
|
72
|
-
|
73
|
-
it { @check_result.should be_error }
|
74
|
-
end
|
75
|
-
|
76
|
-
context "when level is warning" do
|
77
|
-
before(:each) do
|
78
|
-
@check_result = CheckResult.new("1", "message", Rule::ERROR_LEVELS[:warning])
|
79
|
-
end
|
80
|
-
|
81
|
-
it { @check_result.should_not be_error }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe CheckResult, "#warning?" do
|
86
|
-
context "when level is error" do
|
87
|
-
before(:each) do
|
88
|
-
@check_result = CheckResult.new("1", "message", Rule::ERROR_LEVELS[:error])
|
89
|
-
end
|
90
|
-
|
91
|
-
it { @check_result.should_not be_warning }
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when level is warning" do
|
95
|
-
before(:each) do
|
96
|
-
@check_result = CheckResult.new("1", "message", Rule::ERROR_LEVELS[:warning])
|
97
|
-
end
|
98
|
-
|
99
|
-
it { @check_result.should be_warning }
|
100
|
-
end
|
101
|
-
end
|
@@ -1,273 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::Checker
|
4
|
-
require "anodator/checker"
|
5
|
-
|
6
|
-
include Anodator
|
7
|
-
include Anodator::Validator
|
8
|
-
|
9
|
-
describe Checker, ".new" do
|
10
|
-
before(:each) do
|
11
|
-
@input_spec = InputSpec.new([
|
12
|
-
{ :number => "0", :name => "ID" },
|
13
|
-
{ :number => "1", :name => "First name" },
|
14
|
-
{ :number => "2", :name => "Family name" },
|
15
|
-
{ :number => "3", :name => "Birthday" },
|
16
|
-
{ :number => "4", :name => "Sex" },
|
17
|
-
{ :number => "5", :name => "Phone number" },
|
18
|
-
{ :number => "6", :name => "ZIP" },
|
19
|
-
])
|
20
|
-
@rule_set = RuleSet.new
|
21
|
-
# First name
|
22
|
-
validator =
|
23
|
-
ComplexValidator.new(:validators => [LengthValidator.new("1", :in => 3..25),
|
24
|
-
FormatValidator.new("1", :format => /^[a-z]+$/i)])
|
25
|
-
@rule_set << Rule.new("First name",
|
26
|
-
Message.new("[[1::name]] is invalid."),
|
27
|
-
validator)
|
28
|
-
# Family name
|
29
|
-
validator =
|
30
|
-
ComplexValidator.new(:validators => [LengthValidator.new("2", :in => 3..25),
|
31
|
-
FormatValidator.new("2", :format => /^[a-z]+$/i)])
|
32
|
-
@rule_set << Rule.new("Family name",
|
33
|
-
Message.new("[[2::name]] is invalid."),
|
34
|
-
validator)
|
35
|
-
# Birthday
|
36
|
-
@rule_set << Rule.new("Birthday",
|
37
|
-
Message.new("[[3::name]] is invalid."),
|
38
|
-
FormatValidator.new("3", :format => /^\d{4}-\d{2}-\d{2}$/))
|
39
|
-
# Sex
|
40
|
-
@rule_set << Rule.new("Sex",
|
41
|
-
Message.new("[[4::name]] is invalid."),
|
42
|
-
InclusionValidator.new("4", :in => %W(M F)))
|
43
|
-
# Phone number
|
44
|
-
@rule_set << Rule.new("Phone number",
|
45
|
-
Message.new("[[5::name]] is invalid."),
|
46
|
-
FormatValidator.new("5", :format => /^\d+-\d+-\d$/, :allow_blank => true))
|
47
|
-
# ZIP
|
48
|
-
@rule_set << Rule.new("ZIP",
|
49
|
-
Message.new("[[6::name]] is invalid."),
|
50
|
-
FormatValidator.new("6", :format => /^\d{3}-\d{4}$/, :allow_blank => true))
|
51
|
-
@error_list_output_spec = OutputSpec.new([
|
52
|
-
"ID",
|
53
|
-
:error_level,
|
54
|
-
:target_numbers,
|
55
|
-
:error_message,
|
56
|
-
],
|
57
|
-
:target => OutputSpec::TARGET_ERROR,
|
58
|
-
:include_no_error => true)
|
59
|
-
@error_report_output_spec = OutputSpec.new([
|
60
|
-
"ID",
|
61
|
-
:error_count,
|
62
|
-
:warning_count,
|
63
|
-
:error_and_warning_count,
|
64
|
-
],
|
65
|
-
:target => OutputSpec::TARGET_DATA)
|
66
|
-
@valid_values = %W(1 Tetsuhisa MAKINO 1980-01-25 M 1-2-3 123-3456)
|
67
|
-
@invalid_values = ["1", "te", "ma", "1980/01/25", "C", "000000000000", "1234-567"]
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with no parameter" do
|
71
|
-
it "should raise ArgumentError" do
|
72
|
-
lambda {
|
73
|
-
Checker.new
|
74
|
-
}.should raise_error ArgumentError
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "with only input_spec" do
|
79
|
-
it "should raise ArgumentError" do
|
80
|
-
lambda {
|
81
|
-
Checker.new(@input_spec)
|
82
|
-
}.should raise_error ArgumentError
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "with input_spec and rule_set" do
|
87
|
-
it "should raise ArgumentError" do
|
88
|
-
lambda {
|
89
|
-
Checker.new(@input_spec, @rule_set)
|
90
|
-
}.should raise_error ArgumentError
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "with input_spec, rule_set and default_output_spec" do
|
95
|
-
it "should not raise error" do
|
96
|
-
lambda {
|
97
|
-
Checker.new(@input_spec, @rule_set, @error_list_output_spec)
|
98
|
-
}.should_not raise_error
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "on after creation" do
|
104
|
-
before(:each) do
|
105
|
-
@input_spec = InputSpec.new([
|
106
|
-
{ :number => "0", :name => "ID" },
|
107
|
-
{ :number => "1", :name => "First name" },
|
108
|
-
{ :number => "2", :name => "Family name" },
|
109
|
-
{ :number => "3", :name => "Birthday" },
|
110
|
-
{ :number => "4", :name => "Sex" },
|
111
|
-
{ :number => "5", :name => "Phone number" },
|
112
|
-
{ :number => "6", :name => "ZIP" },
|
113
|
-
])
|
114
|
-
@rule_set = RuleSet.new
|
115
|
-
# First name
|
116
|
-
validator =
|
117
|
-
ComplexValidator.new(:validators => [LengthValidator.new("1", :in => 3..25),
|
118
|
-
FormatValidator.new("1", :format => /^[a-z]+$/i)])
|
119
|
-
@rule_set << Rule.new("First name",
|
120
|
-
Message.new("[[1::name]] is invalid."),
|
121
|
-
validator)
|
122
|
-
# Family name
|
123
|
-
validator =
|
124
|
-
ComplexValidator.new(:validators => [LengthValidator.new("2", :in => 3..25),
|
125
|
-
FormatValidator.new("2", :format => /^[a-z]+$/i)])
|
126
|
-
@rule_set << Rule.new("Family name",
|
127
|
-
Message.new("[[2::name]] is invalid."),
|
128
|
-
validator)
|
129
|
-
# Birthday
|
130
|
-
@rule_set << Rule.new("Birthday",
|
131
|
-
Message.new("[[3::name]] is invalid."),
|
132
|
-
FormatValidator.new("3", :format => /^\d{4}-\d{2}-\d{2}$/))
|
133
|
-
# Sex
|
134
|
-
@rule_set << Rule.new("Sex",
|
135
|
-
Message.new("[[4::name]] is invalid."),
|
136
|
-
InclusionValidator.new("4", :in => %W(M F)))
|
137
|
-
# Phone number
|
138
|
-
@rule_set << Rule.new("Phone number",
|
139
|
-
Message.new("[[5::name]] is invalid."),
|
140
|
-
FormatValidator.new("5", :format => /^\d+-\d+-\d$/, :allow_blank => true))
|
141
|
-
# ZIP
|
142
|
-
@rule_set << Rule.new("ZIP",
|
143
|
-
Message.new("[[6::name]] is invalid."),
|
144
|
-
FormatValidator.new("6", :format => /^\d{3}-\d{4}$/, :allow_blank => true))
|
145
|
-
@error_list_output_spec = OutputSpec.new([
|
146
|
-
"ID",
|
147
|
-
:error_level,
|
148
|
-
:target_numbers,
|
149
|
-
:error_message,
|
150
|
-
],
|
151
|
-
:target => OutputSpec::TARGET_ERROR,
|
152
|
-
:include_no_error => true)
|
153
|
-
@error_report_output_spec = OutputSpec.new([
|
154
|
-
"ID",
|
155
|
-
:error_count,
|
156
|
-
:warning_count,
|
157
|
-
:error_and_warning_count,
|
158
|
-
],
|
159
|
-
:target => OutputSpec::TARGET_DATA)
|
160
|
-
@valid_values = %W(1 Tetsuhisa MAKINO 1980-01-25 M 1-2-3 123-3456)
|
161
|
-
@invalid_values = ["1", "te", "ma", "1980/01/25", "C", "000000000000", "1234-567"]
|
162
|
-
|
163
|
-
@checker = Checker.new(@input_spec, @rule_set, @error_list_output_spec)
|
164
|
-
end
|
165
|
-
|
166
|
-
describe "#add_output_spec" do
|
167
|
-
before(:each) do
|
168
|
-
@proc = lambda {
|
169
|
-
@checker.add_output_spec(@error_report_output_spec)
|
170
|
-
}
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should not raise error" do
|
174
|
-
@proc.should_not raise_error
|
175
|
-
end
|
176
|
-
|
177
|
-
context "after process" do
|
178
|
-
before(:each) do
|
179
|
-
@proc.call
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should have 2 output_specs" do
|
183
|
-
@checker.instance_eval("@output_specs.size").should == 2
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "#run" do
|
189
|
-
before(:each) do
|
190
|
-
@checker.add_output_spec(@error_report_output_spec)
|
191
|
-
end
|
192
|
-
|
193
|
-
context "with valid values" do
|
194
|
-
before(:each) do
|
195
|
-
@proc = lambda {
|
196
|
-
@checker.run(@valid_values)
|
197
|
-
}
|
198
|
-
end
|
199
|
-
|
200
|
-
it { @proc.should_not raise_error }
|
201
|
-
|
202
|
-
it "should return 2 outputs" do
|
203
|
-
@proc.call.size.should == 2
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
context "with invalid values" do
|
208
|
-
before(:each) do
|
209
|
-
@proc = lambda {
|
210
|
-
@checker.run(@invalid_values)
|
211
|
-
}
|
212
|
-
end
|
213
|
-
|
214
|
-
it { @proc.should_not raise_error }
|
215
|
-
|
216
|
-
it "should return 2 outputs" do
|
217
|
-
@proc.call.size.should == 2
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe "#validate_configuration" do
|
223
|
-
context "when include invalid rule" do
|
224
|
-
before(:each) do
|
225
|
-
@rule_set << Rule.new("Unknown",
|
226
|
-
Message.new("message"),
|
227
|
-
FormatValidator.new("3", :format => //))
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should raise InvalidConfiguration" do
|
231
|
-
lambda {
|
232
|
-
Checker.new(@input_spec,
|
233
|
-
@rule_set,
|
234
|
-
@error_list_output_spec, true)
|
235
|
-
}.should raise_error InvalidConfiguration
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context "when include invalid output spec" do
|
240
|
-
before(:each) do
|
241
|
-
@invalid_output_spec = OutputSpec.new(["Unknown"])
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should raise InvalidConfiguration" do
|
245
|
-
lambda {
|
246
|
-
Checker.new(@input_spec,
|
247
|
-
@rule_set,
|
248
|
-
@invalid_output_spec, true)
|
249
|
-
}.should raise_error InvalidConfiguration
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe "#rule_info" do
|
255
|
-
before(:each) do
|
256
|
-
@checker.add_output_spec(@error_report_output_spec)
|
257
|
-
end
|
258
|
-
|
259
|
-
context "with valid values" do
|
260
|
-
before(:each) do
|
261
|
-
@proc = lambda {
|
262
|
-
@checker.rule_info
|
263
|
-
}
|
264
|
-
end
|
265
|
-
|
266
|
-
it { @proc.should_not raise_error }
|
267
|
-
|
268
|
-
it "should return 2 outputs" do
|
269
|
-
@proc.call.should be_a String
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|