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
data/spec/anodator/rule_spec.rb
DELETED
@@ -1,278 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::Rule
|
4
|
-
require "anodator/rule"
|
5
|
-
|
6
|
-
include Anodator
|
7
|
-
|
8
|
-
describe Rule, "#new" do
|
9
|
-
context "with no parameters" do
|
10
|
-
it "should raise ArgumentError" do
|
11
|
-
lambda {
|
12
|
-
Rule.new
|
13
|
-
}.should raise_error ArgumentError
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "with only target_expressions" do
|
18
|
-
it "should raise ArgumentError" do
|
19
|
-
lambda {
|
20
|
-
Rule.new(["1", "2", "3"])
|
21
|
-
}.should raise_error ArgumentError
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with target_expressions and message" do
|
26
|
-
it "should raise ArgumentError" do
|
27
|
-
lambda {
|
28
|
-
Rule.new(["1", "2", "3"],
|
29
|
-
Message.new("'[[1::name]]' cannot be blank"))
|
30
|
-
}.should raise_error ArgumentError
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with target_expressions, message and validator" do
|
35
|
-
before(:each) do
|
36
|
-
@new_proc = lambda {
|
37
|
-
v1 = Validator::PresenceValidator.new("1")
|
38
|
-
v2 = Validator::PresenceValidator.new("2")
|
39
|
-
@validator = Validator::ComplexValidator.new(:validators => [v1, v2])
|
40
|
-
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
41
|
-
Rule.new(["1", "2"], @message, @validator)
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should not raise Error" do
|
46
|
-
@new_proc.should_not raise_error
|
47
|
-
end
|
48
|
-
|
49
|
-
context "after generated" do
|
50
|
-
before(:each) do
|
51
|
-
@rule = @new_proc.call
|
52
|
-
end
|
53
|
-
|
54
|
-
it "#target_expressions should equal by initialize" do
|
55
|
-
@rule.target_expressions.should == ["1", "2"]
|
56
|
-
end
|
57
|
-
|
58
|
-
it "#message should equal by initialize" do
|
59
|
-
@rule.message.should == @message
|
60
|
-
end
|
61
|
-
|
62
|
-
it "#validator should equal by initialize" do
|
63
|
-
@rule.validator.should == @validator
|
64
|
-
end
|
65
|
-
|
66
|
-
it "#prerequisite should be nil" do
|
67
|
-
@rule.prerequisite.should be_nil
|
68
|
-
end
|
69
|
-
|
70
|
-
it "#level should equal by default(ERROR_LEVELS[:error])" do
|
71
|
-
@rule.level.should == Rule::ERROR_LEVELS[:error]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "with all parameters" do
|
77
|
-
before(:each) do
|
78
|
-
@new_proc = lambda {
|
79
|
-
v1 = Validator::PresenceValidator.new("1")
|
80
|
-
v2 = Validator::PresenceValidator.new("2")
|
81
|
-
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
82
|
-
@validator = Validator::ComplexValidator.new(:validators => [v1, v2])
|
83
|
-
@prerequisite = Validator::BlankValidator.new("3")
|
84
|
-
Rule.new(["1", "2"], @message, @validator, @prerequisite, Rule::ERROR_LEVELS[:warning])
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should not raise Error" do
|
89
|
-
@new_proc.should_not raise_error
|
90
|
-
end
|
91
|
-
|
92
|
-
context "after generated" do
|
93
|
-
before(:each) do
|
94
|
-
@rule = @new_proc.call
|
95
|
-
end
|
96
|
-
|
97
|
-
it "#target_expressions should equal by initialize" do
|
98
|
-
@rule.target_expressions.should == ["1", "2"]
|
99
|
-
end
|
100
|
-
|
101
|
-
it "#message should equal by initialize" do
|
102
|
-
@rule.message.should == @message
|
103
|
-
end
|
104
|
-
|
105
|
-
it "#validator should equal by initialize" do
|
106
|
-
@rule.validator.should == @validator
|
107
|
-
end
|
108
|
-
|
109
|
-
it "#prerequisite should equal by initialize" do
|
110
|
-
@rule.prerequisite.should == @prerequisite
|
111
|
-
end
|
112
|
-
|
113
|
-
it "#level should equal by initialize" do
|
114
|
-
@rule.level.should == Rule::ERROR_LEVELS[:warning]
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "with multiple prerequisite" do
|
120
|
-
before(:each) do
|
121
|
-
@new_proc = lambda {
|
122
|
-
v1 = Validator::PresenceValidator.new("1")
|
123
|
-
v2 = Validator::PresenceValidator.new("2")
|
124
|
-
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
125
|
-
@validator = Validator::ComplexValidator.new(:validators => [v1, v2])
|
126
|
-
@prerequisites = [
|
127
|
-
Validator::BlankValidator.new("3"),
|
128
|
-
Validator::BlankValidator.new("4")
|
129
|
-
]
|
130
|
-
|
131
|
-
Rule.new(["1", "2"], @message, @validator, @prerequisites, Rule::ERROR_LEVELS[:warning])
|
132
|
-
}
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should not raise Error" do
|
136
|
-
@new_proc.should_not raise_error
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe Rule, "#check" do
|
142
|
-
before(:each) do
|
143
|
-
@input_spec = InputSpec.new([
|
144
|
-
{ :number => "1", :name => "item_1" },
|
145
|
-
{ :number => "2", :name => "item_2" },
|
146
|
-
{ :number => "3", :name => "item_3" },
|
147
|
-
])
|
148
|
-
v1 = Validator::PresenceValidator.new("1")
|
149
|
-
v2 = Validator::PresenceValidator.new("2")
|
150
|
-
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
151
|
-
@validator = Validator::ComplexValidator.new(:validators => [v1, v2], :logic => Validator::ComplexValidator::LOGIC_AND)
|
152
|
-
@prerequisite = Validator::BlankValidator.new("3")
|
153
|
-
@rule = Rule.new(["item_1", "2"], @message, @validator, @prerequisite)
|
154
|
-
end
|
155
|
-
|
156
|
-
context "when check rule is valid" do
|
157
|
-
before(:each) do
|
158
|
-
@input_spec.source = ["1", "2", ""]
|
159
|
-
Validator::Base.values = @input_spec
|
160
|
-
end
|
161
|
-
|
162
|
-
it { @rule.check.should be_nil }
|
163
|
-
end
|
164
|
-
|
165
|
-
context "when check rule is not valid" do
|
166
|
-
before(:each) do
|
167
|
-
@input_spec.source = ["1", "", ""]
|
168
|
-
Validator::Base.values = @input_spec
|
169
|
-
end
|
170
|
-
|
171
|
-
it { @rule.check.should_not be_nil }
|
172
|
-
it { @rule.check.should be_a CheckResult }
|
173
|
-
|
174
|
-
it "CheckResult#target_numbers must be only number expression" do
|
175
|
-
result = @rule.check
|
176
|
-
result.target_numbers.each do |number|
|
177
|
-
@input_spec.spec_item_by_expression(number).number.should == number
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context "when prerequisite not matched" do
|
183
|
-
before(:each) do
|
184
|
-
@input_spec.source = ["1", "", "3"]
|
185
|
-
Validator::Base.values = @input_spec
|
186
|
-
end
|
187
|
-
|
188
|
-
it { @rule.check.should be_nil }
|
189
|
-
end
|
190
|
-
|
191
|
-
context "with complex prerequisite" do
|
192
|
-
before(:each) do
|
193
|
-
@input_spec = InputSpec.new([
|
194
|
-
{ :number => "1", :name => "item_1" },
|
195
|
-
{ :number => "2", :name => "item_2" },
|
196
|
-
{ :number => "3", :name => "item_3" },
|
197
|
-
{ :number => "4", :name => "item_4" },
|
198
|
-
])
|
199
|
-
v1 = Validator::PresenceValidator.new("1")
|
200
|
-
v2 = Validator::PresenceValidator.new("2")
|
201
|
-
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
202
|
-
@validator = Validator::ComplexValidator.new(:validators => [v1, v2], :logic => Validator::ComplexValidator::LOGIC_AND)
|
203
|
-
@prerequisites = [
|
204
|
-
Validator::BlankValidator.new("3"),
|
205
|
-
Validator::BlankValidator.new("4")
|
206
|
-
]
|
207
|
-
@rule = Rule.new(["item_1", "2"], @message, @validator, @prerequisites)
|
208
|
-
end
|
209
|
-
|
210
|
-
context "when prerequisites matches and invalid" do
|
211
|
-
before(:each) do
|
212
|
-
@input_spec.source = ["1", "", "", ""]
|
213
|
-
Validator::Base.values = @input_spec
|
214
|
-
end
|
215
|
-
|
216
|
-
it { @rule.check.should be_a CheckResult }
|
217
|
-
end
|
218
|
-
|
219
|
-
context "when prerequisites matches and valid" do
|
220
|
-
before(:each) do
|
221
|
-
@input_spec.source = ["1", "2", "", ""]
|
222
|
-
Validator::Base.values = @input_spec
|
223
|
-
end
|
224
|
-
|
225
|
-
it { @rule.check.should be_nil }
|
226
|
-
end
|
227
|
-
|
228
|
-
context "when prerequisites not matches and valid" do
|
229
|
-
before(:each) do
|
230
|
-
@input_spec.source = ["1", "2", "", "4"]
|
231
|
-
Validator::Base.values = @input_spec
|
232
|
-
end
|
233
|
-
|
234
|
-
it { @rule.check.should be_nil }
|
235
|
-
end
|
236
|
-
|
237
|
-
context "when prerequisites not matches and invalid" do
|
238
|
-
before(:each) do
|
239
|
-
@input_spec.source = ["1", "2", "", "4"]
|
240
|
-
Validator::Base.values = @input_spec
|
241
|
-
end
|
242
|
-
|
243
|
-
it { @rule.check.should be_nil }
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe Rule, ".add_error_level" do
|
249
|
-
context "when new valid error level" do
|
250
|
-
before(:each) do
|
251
|
-
@proc = lambda {
|
252
|
-
Rule.add_error_level(3, :fatal, "FATAL")
|
253
|
-
}
|
254
|
-
end
|
255
|
-
|
256
|
-
after(:each) do
|
257
|
-
Rule.remove_error_level(:fatal)
|
258
|
-
end
|
259
|
-
|
260
|
-
it "should not raise error" do
|
261
|
-
lambda {
|
262
|
-
@proc.call
|
263
|
-
}.should_not raise_error
|
264
|
-
end
|
265
|
-
|
266
|
-
it "should 3 error levels" do
|
267
|
-
lambda {
|
268
|
-
@proc.call
|
269
|
-
}.should change(Rule::ERROR_LEVELS, :size).from(2).to(3)
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should 3 error level names" do
|
273
|
-
lambda {
|
274
|
-
@proc.call
|
275
|
-
}.should change(Rule::ERROR_LEVEL_NAMES, :size).from(2).to(3)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
data/spec/anodator/utils_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "tempfile"
|
3
|
-
|
4
|
-
# Anodator::Utils
|
5
|
-
require "anodator"
|
6
|
-
require "anodator/utils"
|
7
|
-
|
8
|
-
include Anodator
|
9
|
-
|
10
|
-
describe Utils, ".load_input_spec_from_csv_file" do
|
11
|
-
context "read valid file" do
|
12
|
-
before(:each) do
|
13
|
-
@file = Tempfile.new(["input_spec", ".csv"])
|
14
|
-
|
15
|
-
# Header
|
16
|
-
@file.puts(["id", "name", "type"].join(","))
|
17
|
-
# values
|
18
|
-
@values = [
|
19
|
-
{ :id => "1", :name => "Name", :type => "STRING" },
|
20
|
-
{ :id => "2", :name => "Age", :type => "NUMERIC" },
|
21
|
-
{ :id => "3", :name => "Birtyday", :type => "DATE" },
|
22
|
-
{ :id => "4", :name => "Sex", :type => "NUMERIC" },
|
23
|
-
{ :id => "5", :name => "Email", :type => "STRING" },
|
24
|
-
]
|
25
|
-
@values.each do |v|
|
26
|
-
@file.puts("#{v[:id]},#{v[:name]},#{v[:type]}")
|
27
|
-
end
|
28
|
-
@file.close
|
29
|
-
|
30
|
-
@proc = lambda {
|
31
|
-
Utils.load_input_spec_from_csv_file(@file.path)
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
after(:each) do
|
36
|
-
@file.unlink
|
37
|
-
end
|
38
|
-
|
39
|
-
it { @proc.should_not raise_error }
|
40
|
-
|
41
|
-
it "should have all items" do
|
42
|
-
input_spec = @proc.call
|
43
|
-
@values.each do |value|
|
44
|
-
input_spec.spec_item_by_expression(value[:id]).should_not be_nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,214 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::Validator::Base
|
4
|
-
require "anodator/validator/base"
|
5
|
-
|
6
|
-
describe Anodator::Validator::Base, "#new" do
|
7
|
-
context "with no parameters" do
|
8
|
-
it "should raise ArgumentError" do
|
9
|
-
lambda {
|
10
|
-
Anodator::Validator::Base.new
|
11
|
-
}.should raise_error ArgumentError
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "with only target(nil) parameter" do
|
16
|
-
it "should raise ArgumentError" do
|
17
|
-
lambda {
|
18
|
-
Anodator::Validator::Base.new(nil)
|
19
|
-
}.should raise_error ArgumentError
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "with only target("") parameter" do
|
24
|
-
it "should raise ArgumentError" do
|
25
|
-
lambda {
|
26
|
-
Anodator::Validator::Base.new("")
|
27
|
-
}.should raise_error ArgumentError
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "with only target(34) parameter" do
|
32
|
-
before(:each) do
|
33
|
-
@new_proc = lambda {
|
34
|
-
Anodator::Validator::Base.new("34")
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should not raise ArgumentError" do
|
39
|
-
@new_proc.should_not raise_error ArgumentError
|
40
|
-
end
|
41
|
-
|
42
|
-
it "#allow_blank? should be false" do
|
43
|
-
@base = @new_proc.call
|
44
|
-
@base.should_not be_allow_blank
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "with target(name) parameter" do
|
49
|
-
context "and allow_blank(true) parameter" do
|
50
|
-
before(:each) do
|
51
|
-
@new_proc = lambda {
|
52
|
-
Anodator::Validator::Base.new("name", :allow_blank => true)
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should not raise ArgumentError" do
|
57
|
-
@new_proc.should_not raise_error ArgumentError
|
58
|
-
end
|
59
|
-
|
60
|
-
it "#allow_blank? should be true" do
|
61
|
-
@base = @new_proc.call
|
62
|
-
@base.should be_allow_blank
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "and allow_blank(false) parameter" do
|
67
|
-
before(:each) do
|
68
|
-
@new_proc = lambda {
|
69
|
-
Anodator::Validator::Base.new("name", :allow_blank => false)
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should not raise ArgumentError" do
|
74
|
-
@new_proc.should_not raise_error ArgumentError
|
75
|
-
end
|
76
|
-
|
77
|
-
it "#allow_blank? should be false" do
|
78
|
-
@base = @new_proc.call
|
79
|
-
@base.should_not be_allow_blank
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "and description parameter" do
|
84
|
-
before(:each) do
|
85
|
-
@new_proc = lambda {
|
86
|
-
Anodator::Validator::Base.new("name", :description => "description message here.")
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should not raise ArgumentError" do
|
91
|
-
@new_proc.should_not raise_error ArgumentError
|
92
|
-
end
|
93
|
-
|
94
|
-
it "#description should be 'description message here.'" do
|
95
|
-
@base = @new_proc.call
|
96
|
-
@base.description.should == "description message here."
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "and unknown parameter" do
|
101
|
-
before(:each) do
|
102
|
-
@new_proc = lambda {
|
103
|
-
Anodator::Validator::Base.new("name", :unknown => "value")
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should raise ArgumentError" do
|
108
|
-
@new_proc.should raise_error ArgumentError
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe Anodator::Validator::Base, "#validate" do
|
115
|
-
it "Anodator::Validator::Base#validate raise NotImplementedError" do
|
116
|
-
lambda {
|
117
|
-
Anodator::Validator::Base.new("1").validate
|
118
|
-
}.should raise_error NoMethodError
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe Anodator::Validator::Base, "create a new Validator class to inherit" do
|
123
|
-
before(:all) do
|
124
|
-
module Anodator
|
125
|
-
module Validator
|
126
|
-
class SomeValidator < Base
|
127
|
-
valid_option_keys :some_option
|
128
|
-
default_options :some_option => true
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should have additional option" do
|
135
|
-
Anodator::Validator::SomeValidator.valid_option_keys.
|
136
|
-
should be_include(:some_option)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should have default option ':allow_blank'" do
|
140
|
-
Anodator::Validator::SomeValidator.valid_option_keys.
|
141
|
-
should be_include(:allow_blank)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should have default value is true for option 'some_option'" do
|
145
|
-
Anodator::Validator::SomeValidator.default_options[:some_option].
|
146
|
-
should be_true
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe Anodator::Validator::Base, "create a new Validator class with unknown defualt options" do
|
151
|
-
before(:all) do
|
152
|
-
@new_class_proc = lambda {
|
153
|
-
module Anodator
|
154
|
-
module Validator
|
155
|
-
class InvalidDefaultOptionValidator < Base
|
156
|
-
valid_option_keys :some_option
|
157
|
-
default_options :wrong_option => 11
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
}
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should raise error" do
|
165
|
-
@new_class_proc.should raise_error ArgumentError
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe Anodator::Validator::Base, "set values for validation" do
|
170
|
-
context "for nil value" do
|
171
|
-
it "should raise argument error" do
|
172
|
-
lambda {
|
173
|
-
Anodator::Validator::Base.values = nil
|
174
|
-
}.should raise_error ArgumentError
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context "for String value" do
|
179
|
-
it "should not raise argument error" do
|
180
|
-
lambda {
|
181
|
-
Anodator::Validator::Base.values = "value"
|
182
|
-
}.should_not raise_error ArgumentError
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "for Array values" do
|
187
|
-
it "should not raise argument error" do
|
188
|
-
lambda {
|
189
|
-
Anodator::Validator::Base.values = [1, 2, 3]
|
190
|
-
}.should_not raise_error ArgumentError
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
context "for Hash values" do
|
195
|
-
it "should not raise argument error" do
|
196
|
-
lambda {
|
197
|
-
Anodator::Validator::Base.values = { "1" => 1, "2" => 2, "3" => 3 }
|
198
|
-
}.should_not raise_error ArgumentError
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "for another values what can respond to [] method" do
|
203
|
-
it "should not raise argument error" do
|
204
|
-
lambda {
|
205
|
-
class Dict
|
206
|
-
def []
|
207
|
-
return ""
|
208
|
-
end
|
209
|
-
end
|
210
|
-
Anodator::Validator::Base.values = Dict.new
|
211
|
-
}.should_not raise_error ArgumentError
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::Validator::BlankValidator
|
4
|
-
require "anodator/validator/blank_validator"
|
5
|
-
|
6
|
-
describe Anodator::Validator::BlankValidator, ".new" do
|
7
|
-
context "with no parameters" do
|
8
|
-
it "should raise ArgumentError" do
|
9
|
-
lambda {
|
10
|
-
Anodator::Validator::BlankValidator.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::BlankValidator.new("1")
|
19
|
-
}.should_not raise_error
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe Anodator::Validator::BlankValidator, "#valid?" do
|
25
|
-
before(:each) do
|
26
|
-
@validator = Anodator::Validator::BlankValidator.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 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_not 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_not be_valid }
|
51
|
-
end
|
52
|
-
end
|