sequel_spec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +1 -0
- data/lib/sequel_spec.rb +8 -0
- data/lib/sequel_spec/association.rb +13 -0
- data/lib/sequel_spec/association/association_matcher.rb +32 -0
- data/lib/sequel_spec/association/have_many_to_many_matcher.rb +15 -0
- data/lib/sequel_spec/association/have_many_to_one_matcher.rb +15 -0
- data/lib/sequel_spec/association/have_one_through_one_matcher.rb +15 -0
- data/lib/sequel_spec/association/have_one_to_many_matcher.rb +15 -0
- data/lib/sequel_spec/association/have_one_to_one_matcher.rb +15 -0
- data/lib/sequel_spec/base.rb +45 -0
- data/lib/sequel_spec/integration/rspec.rb +6 -0
- data/lib/sequel_spec/validation.rb +18 -0
- data/lib/sequel_spec/validation/validate_format_matcher.rb +42 -0
- data/lib/sequel_spec/validation/validate_includes_matcher.rb +43 -0
- data/lib/sequel_spec/validation/validate_integer_matcher.rb +23 -0
- data/lib/sequel_spec/validation/validate_length_matcher.rb +81 -0
- data/lib/sequel_spec/validation/validate_matcher.rb +67 -0
- data/lib/sequel_spec/validation/validate_not_null_matcher.rb +21 -0
- data/lib/sequel_spec/validation/validate_numeric_matcher.rb +23 -0
- data/lib/sequel_spec/validation/validate_presence_matcher.rb +23 -0
- data/lib/sequel_spec/validation/validate_schema_types_matcher.rb +23 -0
- data/lib/sequel_spec/validation/validate_type_matcher.rb +42 -0
- data/lib/sequel_spec/validation/validate_unique_matcher.rb +31 -0
- data/lib/sequel_spec/version.rb +3 -0
- data/sequel_spec.gemspec +25 -0
- data/spec/migrations/001_create_tables.rb +26 -0
- data/spec/sequel_spec/association/have_many_to_many_matcher_spec.rb +57 -0
- data/spec/sequel_spec/association/have_many_to_one_matcher_spec.rb +57 -0
- data/spec/sequel_spec/association/have_one_through_one_matcher_spec.rb +57 -0
- data/spec/sequel_spec/association/have_one_to_many_matcher_spec.rb +57 -0
- data/spec/sequel_spec/association/have_one_to_one_matcher_spec.rb +57 -0
- data/spec/sequel_spec/validation/validate_format_matcher_spec.rb +88 -0
- data/spec/sequel_spec/validation/validate_includes_matcher_spec.rb +88 -0
- data/spec/sequel_spec/validation/validate_integer_matcher_spec.rb +76 -0
- data/spec/sequel_spec/validation/validate_length_matcher_spec.rb +252 -0
- data/spec/sequel_spec/validation/validate_not_null_matcher_spec.rb +83 -0
- data/spec/sequel_spec/validation/validate_numeric_matcher_spec.rb +76 -0
- data/spec/sequel_spec/validation/validate_presence_matcher_spec.rb +77 -0
- data/spec/sequel_spec/validation/validate_schema_types_matcher_spec.rb +83 -0
- data/spec/sequel_spec/validation/validate_type_matcher_spec.rb +88 -0
- data/spec/sequel_spec/validation/validate_unique_matcher_spec.rb +83 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/test_helpers.rb +19 -0
- metadata +164 -0
@@ -0,0 +1,252 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_length_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_length_range 1..10, :manufacturer, :allow_nil => true
|
10
|
+
validates_exact_length 4, :name, :allow_nil => true
|
11
|
+
validates_min_length 4, :owner, :allow_nil => true
|
12
|
+
validates_max_length 4, :origin, :allow_nil => true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject{ Item }
|
18
|
+
|
19
|
+
it "should require an attribute" do
|
20
|
+
expect {
|
21
|
+
subject.should validate_length_of
|
22
|
+
}.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should require additionnal parameters" do
|
26
|
+
expect {
|
27
|
+
subject.should validate_length_of(:name)
|
28
|
+
}.to raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should accept with valid parameters and options" do
|
32
|
+
expect {
|
33
|
+
subject.should validate_length_of(:name).is(4).allowing_nil
|
34
|
+
}.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should reject with valid parameters but invalid options" do
|
38
|
+
expect {
|
39
|
+
subject.should validate_length_of(:name).is(4).allowing_blank
|
40
|
+
}.to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with exact length" do
|
44
|
+
it "should accept with valid parameters" do
|
45
|
+
expect {
|
46
|
+
subject.should validate_length_of(:name).is(4)
|
47
|
+
}.not_to raise_error
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should reject with invalid parameters" do
|
51
|
+
expect {
|
52
|
+
subject.should validate_length_of(:name).is(5)
|
53
|
+
}.to raise_error
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with length range" do
|
58
|
+
it "should accept with valid parameters" do
|
59
|
+
expect {
|
60
|
+
subject.should validate_length_of(:manufacturer).is_between(1..10)
|
61
|
+
}.not_to raise_error
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should reject with invalid parameters" do
|
65
|
+
expect {
|
66
|
+
subject.should validate_length_of(:manufacturer).is_between(1..20)
|
67
|
+
}.to raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with minimum length" do
|
72
|
+
it "should accept with valid parameters" do
|
73
|
+
expect {
|
74
|
+
subject.should validate_length_of(:owner).is_at_least(4)
|
75
|
+
}.not_to raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should reject with invalid parameters" do
|
79
|
+
expect {
|
80
|
+
subject.should validate_length_of(:owner).is_at_least(8)
|
81
|
+
}.to raise_error
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with maximum length" do
|
86
|
+
it "should accept with valid parameters" do
|
87
|
+
expect {
|
88
|
+
subject.should validate_length_of(:origin).is_at_most(4)
|
89
|
+
}.not_to raise_error
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should reject with invalid parameters" do
|
93
|
+
expect {
|
94
|
+
subject.should validate_length_of(:origin).is_at_most(8)
|
95
|
+
}.to raise_error
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "messages" do
|
100
|
+
context "with exact length" do
|
101
|
+
describe "without option" do
|
102
|
+
it "should contain a description" do
|
103
|
+
@matcher = validate_length_of(:name).is(4)
|
104
|
+
@matcher.description.should == "validate that length of :name is exactly 4"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should set failure messages" do
|
108
|
+
@matcher = validate_length_of(:name).is(4)
|
109
|
+
@matcher.matches? subject
|
110
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
111
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "with options" do
|
116
|
+
it "should contain a description" do
|
117
|
+
@matcher = validate_length_of(:name).is(4).allowing_nil
|
118
|
+
@matcher.description.should == "validate that length of :name is exactly 4 with option(s) :allow_nil => true"
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should set failure messages" do
|
122
|
+
@matcher = validate_length_of(:price).is(4).allowing_nil
|
123
|
+
@matcher.matches? subject
|
124
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
125
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should explicit used options if different than expected" do
|
129
|
+
@matcher = validate_length_of(:name).is(4).allowing_blank
|
130
|
+
@matcher.matches? subject
|
131
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
132
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
133
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "with length range" do
|
139
|
+
describe "without option" do
|
140
|
+
it "should contain a description" do
|
141
|
+
@matcher = validate_length_of(:manufacturer).is_between(1..10)
|
142
|
+
@matcher.description.should == "validate that length of :manufacturer is included in 1..10"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should set failure messages" do
|
146
|
+
@matcher = validate_length_of(:manufacturer).is_between(1..10)
|
147
|
+
@matcher.matches? subject
|
148
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
149
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "with options" do
|
154
|
+
it "should contain a description" do
|
155
|
+
@matcher = validate_length_of(:manufacturer).is_between(1..10).allowing_nil
|
156
|
+
@matcher.description.should == "validate that length of :manufacturer is included in 1..10 with option(s) :allow_nil => true"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should set failure messages" do
|
160
|
+
@matcher = validate_length_of(:price).is_between(1..10).allowing_nil
|
161
|
+
@matcher.matches? subject
|
162
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
163
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should explicit used options if different than expected" do
|
167
|
+
@matcher = validate_length_of(:manufacturer).is_between(1..10).allowing_blank
|
168
|
+
@matcher.matches? subject
|
169
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
170
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
171
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with minimum range" do
|
177
|
+
describe "without option" do
|
178
|
+
it "should contain a description" do
|
179
|
+
@matcher = validate_length_of(:owner).is_at_least(4)
|
180
|
+
@matcher.description.should == "validate that length of :owner is greater than or equal to 4"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should set failure messages" do
|
184
|
+
@matcher = validate_length_of(:owner).is_at_least(4)
|
185
|
+
@matcher.matches? subject
|
186
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
187
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "with options" do
|
192
|
+
it "should contain a description" do
|
193
|
+
@matcher = validate_length_of(:owner).is_at_least(4).allowing_nil
|
194
|
+
@matcher.description.should == "validate that length of :owner is greater than or equal to 4 with option(s) :allow_nil => true"
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should set failure messages" do
|
198
|
+
@matcher = validate_length_of(:price).is_at_least(4).allowing_nil
|
199
|
+
@matcher.matches? subject
|
200
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
201
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should explicit used options if different than expected" do
|
205
|
+
@matcher = validate_length_of(:owner).is_at_least(4).allowing_blank
|
206
|
+
@matcher.matches? subject
|
207
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
208
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
209
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "with maximum range" do
|
215
|
+
describe "without option" do
|
216
|
+
it "should contain a description" do
|
217
|
+
@matcher = validate_length_of(:origin).is_at_most(4)
|
218
|
+
@matcher.description.should == "validate that length of :origin is less than or equal to 4"
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should set failure messages" do
|
222
|
+
@matcher = validate_length_of(:origin).is_at_most(4)
|
223
|
+
@matcher.matches? subject
|
224
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
225
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "with options" do
|
230
|
+
it "should contain a description" do
|
231
|
+
@matcher = validate_length_of(:origin).is_at_most(4).allowing_nil
|
232
|
+
@matcher.description.should == "validate that length of :origin is less than or equal to 4 with option(s) :allow_nil => true"
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should set failure messages" do
|
236
|
+
@matcher = validate_length_of(:price).is_at_most(4).allowing_nil
|
237
|
+
@matcher.matches? subject
|
238
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
239
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should explicit used options if different than expected" do
|
243
|
+
@matcher = validate_length_of(:origin).is_at_most(4).allowing_blank
|
244
|
+
@matcher.matches? subject
|
245
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
246
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
247
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_not_null_matcher" do
|
4
|
+
before do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_not_null :name, :message => "Hello"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject{ Item }
|
15
|
+
|
16
|
+
it "should require an attribute" do
|
17
|
+
expect {
|
18
|
+
subject.should validate_not_null
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept with an attribute" do
|
23
|
+
expect {
|
24
|
+
subject.should validate_not_null(:name)
|
25
|
+
}.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept with valid options" do
|
29
|
+
expect {
|
30
|
+
subject.should validate_not_null(:name).with_message "Hello"
|
31
|
+
}.not_to raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should reject with options with invalid values" do
|
35
|
+
expect {
|
36
|
+
subject.should validate_not_null(:name).with_message "Bye"
|
37
|
+
}.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should reject with invalid options" do
|
41
|
+
expect {
|
42
|
+
subject.should validate_not_null(:name).allowing_nil
|
43
|
+
}.to raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "messages" do
|
47
|
+
describe "without option" do
|
48
|
+
it "should contain a description" do
|
49
|
+
@matcher = validate_not_null :name
|
50
|
+
@matcher.description.should == "validate that :name is not null"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set failure messages" do
|
54
|
+
@matcher = validate_not_null :name
|
55
|
+
@matcher.matches? subject
|
56
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
57
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "with options" do
|
62
|
+
it "should contain a description" do
|
63
|
+
@matcher = validate_not_null(:name).with_message("Hello")
|
64
|
+
@matcher.description.should == 'validate that :name is not null with option(s) :message => "Hello"'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set failure messages" do
|
68
|
+
@matcher = validate_not_null(:price).with_message("Hello")
|
69
|
+
@matcher.matches? subject
|
70
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
71
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should explicit used options if different than expected" do
|
75
|
+
@matcher = validate_not_null(:name).with_message("Hello world")
|
76
|
+
@matcher.matches? subject
|
77
|
+
explanation = ' but called with option(s) :message => "Hello" instead'
|
78
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
79
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_numeric_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_numeric [:id, :name], :allow_nil => true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject{ Item }
|
15
|
+
|
16
|
+
it "should require an attribute" do
|
17
|
+
expect {
|
18
|
+
subject.should validate_numeric
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept with an attribute" do
|
23
|
+
expect {
|
24
|
+
subject.should validate_numeric(:name)
|
25
|
+
}.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept with valid options" do
|
29
|
+
expect {
|
30
|
+
subject.should validate_numeric(:name).allowing_nil
|
31
|
+
}.not_to raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should reject with invalid options" do
|
35
|
+
expect {
|
36
|
+
subject.should validate_numeric(:name).allowing_blank
|
37
|
+
}.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "messages" do
|
41
|
+
describe "without option" do
|
42
|
+
it "should contain a description" do
|
43
|
+
@matcher = validate_numeric :name
|
44
|
+
@matcher.description.should == "validate that :name is a valid float"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set failure messages" do
|
48
|
+
@matcher = validate_numeric :name
|
49
|
+
@matcher.matches? subject
|
50
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
51
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
52
|
+
end
|
53
|
+
end
|
54
|
+
describe "with options" do
|
55
|
+
it "should contain a description" do
|
56
|
+
@matcher = validate_numeric(:name).allowing_nil
|
57
|
+
@matcher.description.should == "validate that :name is a valid float with option(s) :allow_nil => true"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set failure messages" do
|
61
|
+
@matcher = validate_numeric(:price).allowing_nil
|
62
|
+
@matcher.matches? subject
|
63
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
64
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should explicit used options if different than expected" do
|
68
|
+
@matcher = validate_numeric(:name).allowing_blank
|
69
|
+
@matcher.matches? subject
|
70
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
71
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
72
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_presence_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_presence [:id, :name], :allow_nil => true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject{ Item }
|
15
|
+
|
16
|
+
it "should require an attribute" do
|
17
|
+
expect {
|
18
|
+
subject.should validate_presence
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept with an attribute" do
|
23
|
+
expect {
|
24
|
+
subject.should validate_presence(:name)
|
25
|
+
}.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept with valid options" do
|
29
|
+
expect {
|
30
|
+
subject.should validate_presence(:name).allowing_nil
|
31
|
+
}.not_to raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should reject with invalid options" do
|
35
|
+
expect {
|
36
|
+
subject.should validate_presence(:name).allowing_blank
|
37
|
+
}.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "messages" do
|
41
|
+
describe "without option" do
|
42
|
+
it "should contain a description" do
|
43
|
+
@matcher = validate_presence :name
|
44
|
+
@matcher.description.should == "validate presence of :name"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set failure messages" do
|
48
|
+
@matcher = validate_presence :name
|
49
|
+
@matcher.matches? subject
|
50
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
51
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "with options" do
|
56
|
+
it "should contain a description" do
|
57
|
+
@matcher = validate_presence(:name).allowing_nil
|
58
|
+
@matcher.description.should == "validate presence of :name with option(s) :allow_nil => true"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set failure messages" do
|
62
|
+
@matcher = validate_presence(:price).allowing_nil
|
63
|
+
@matcher.matches? subject
|
64
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
65
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should explicit used options if different than expected" do
|
69
|
+
@matcher = validate_presence(:name).allowing_blank
|
70
|
+
@matcher.matches? subject
|
71
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
72
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
73
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|