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,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "have_many_to_one_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item
|
6
|
+
define_model :comment do
|
7
|
+
many_to_one :item
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
subject{ Comment }
|
12
|
+
|
13
|
+
describe "messages" do
|
14
|
+
describe "without option" do
|
15
|
+
it "should contain a description" do
|
16
|
+
@matcher = have_many_to_one :item
|
17
|
+
@matcher.description.should == "have a many_to_one association :item"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set failure messages" do
|
21
|
+
@matcher = have_many_to_one :item
|
22
|
+
@matcher.matches? subject
|
23
|
+
@matcher.failure_message.should == "expected Comment to " + @matcher.description
|
24
|
+
@matcher.negative_failure_message.should == "expected Comment to not " + @matcher.description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with options" do
|
29
|
+
it "should contain a description" do
|
30
|
+
@matcher = have_many_to_one(:item).with_options :class_name => "Item"
|
31
|
+
@matcher.description.should == 'have a many_to_one association :item with option(s) :class_name => "Item"'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set failure messages" do
|
35
|
+
@matcher = have_many_to_one(:item).with_options :class_name => "Item"
|
36
|
+
@matcher.matches? subject
|
37
|
+
@matcher.failure_message.should == "expected Comment to " + @matcher.description
|
38
|
+
@matcher.negative_failure_message.should == "expected Comment to not " + @matcher.description
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should explicit used options if different than expected" do
|
42
|
+
@matcher = have_many_to_one(:item).with_options :class_name => "Price"
|
43
|
+
@matcher.matches? subject
|
44
|
+
explanation = ' expected :class_name == "Price" but found "Item" instead'
|
45
|
+
@matcher.failure_message.should == "expected Comment to " + @matcher.description + explanation
|
46
|
+
@matcher.negative_failure_message.should == "expected Comment to not " + @matcher.description + explanation
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "matchers" do
|
52
|
+
it{ should have_many_to_one(:item) }
|
53
|
+
it{ should have_many_to_one(:item).with_options :class_name => "Item" }
|
54
|
+
it{ should_not have_many_to_one(:price) }
|
55
|
+
it{ should_not have_many_to_one(:item).with_options :class_name => "Price" }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "have_one_through_one_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
one_through_one :comment
|
7
|
+
end
|
8
|
+
define_model :comment
|
9
|
+
end
|
10
|
+
|
11
|
+
subject{ Item }
|
12
|
+
|
13
|
+
describe "messages" do
|
14
|
+
describe "without option" do
|
15
|
+
it "should contain a description" do
|
16
|
+
@matcher = have_one_through_one :comment
|
17
|
+
@matcher.description.should == "have a one_through_one association :comment"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set failure messages" do
|
21
|
+
@matcher = have_one_through_one :comment
|
22
|
+
@matcher.matches? subject
|
23
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
24
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with options" do
|
29
|
+
it "should contain a description" do
|
30
|
+
@matcher = have_one_through_one(:comment).with_options :class_name => "Comment"
|
31
|
+
@matcher.description.should == 'have a one_through_one association :comment with option(s) :class_name => "Comment"'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set failure messages" do
|
35
|
+
@matcher = have_one_through_one(:comment).with_options :class_name => "Comment"
|
36
|
+
@matcher.matches? subject
|
37
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
38
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should explicit used options if different than expected" do
|
42
|
+
@matcher = have_one_through_one(:comment).with_options :class_name => "Price"
|
43
|
+
@matcher.matches? subject
|
44
|
+
explanation = ' expected :class_name == "Price" but found "Comment" instead'
|
45
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
46
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "matchers" do
|
52
|
+
it{ should have_one_through_one(:comment) }
|
53
|
+
it{ should have_one_through_one(:comment).with_options :class_name => "Comment" }
|
54
|
+
it{ should_not have_one_through_one(:price) }
|
55
|
+
it{ should_not have_one_through_one(:comment).with_options :class_name => "Price" }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "have_one_to_many_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
one_to_many :comments
|
7
|
+
end
|
8
|
+
define_model :comment
|
9
|
+
end
|
10
|
+
|
11
|
+
subject{ Item }
|
12
|
+
|
13
|
+
describe "messages" do
|
14
|
+
describe "without option" do
|
15
|
+
it "should contain a description" do
|
16
|
+
@matcher = have_one_to_many :comments
|
17
|
+
@matcher.description.should == "have a one_to_many association :comments"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set failure messages" do
|
21
|
+
@matcher = have_one_to_many :comments
|
22
|
+
@matcher.matches? subject
|
23
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
24
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with options" do
|
29
|
+
it "should contain a description" do
|
30
|
+
@matcher = have_one_to_many(:comments).with_options :class_name => "Comment"
|
31
|
+
@matcher.description.should == 'have a one_to_many association :comments with option(s) :class_name => "Comment"'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set failure messages" do
|
35
|
+
@matcher = have_one_to_many(:comments).with_options :class_name => "Comment"
|
36
|
+
@matcher.matches? subject
|
37
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
38
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should explicit used options if different than expected" do
|
42
|
+
@matcher = have_one_to_many(:comments).with_options :class_name => "Price"
|
43
|
+
@matcher.matches? subject
|
44
|
+
explanation = ' expected :class_name == "Price" but found "Comment" instead'
|
45
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
46
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "matchers" do
|
52
|
+
it{ should have_one_to_many(:comments) }
|
53
|
+
it{ should have_one_to_many(:comments).with_options :class_name => "Comment" }
|
54
|
+
it{ should_not have_one_to_many(:prices) }
|
55
|
+
it{ should_not have_one_to_many(:comments).with_options :class_name => "Price" }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "have_one_to_one_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
one_to_one :comment
|
7
|
+
end
|
8
|
+
define_model :comment
|
9
|
+
end
|
10
|
+
|
11
|
+
subject{ Item }
|
12
|
+
|
13
|
+
describe "messages" do
|
14
|
+
describe "without option" do
|
15
|
+
it "should contain a description" do
|
16
|
+
@matcher = have_one_to_one :comment
|
17
|
+
@matcher.description.should == "have a one_to_one association :comment"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set failure messages" do
|
21
|
+
@matcher = have_one_to_one :comment
|
22
|
+
@matcher.matches? subject
|
23
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
24
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with options" do
|
29
|
+
it "should contain a description" do
|
30
|
+
@matcher = have_one_to_one(:comment).with_options :class_name => "Comment"
|
31
|
+
@matcher.description.should == 'have a one_to_one association :comment with option(s) :class_name => "Comment"'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set failure messages" do
|
35
|
+
@matcher = have_one_to_one(:comment).with_options :class_name => "Comment"
|
36
|
+
@matcher.matches? subject
|
37
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
38
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should explicit used options if different than expected" do
|
42
|
+
@matcher = have_one_to_one(:comment).with_options :class_name => "Price"
|
43
|
+
@matcher.matches? subject
|
44
|
+
explanation = ' expected :class_name == "Price" but found "Comment" instead'
|
45
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
46
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "matchers" do
|
52
|
+
it{ should have_one_to_one(:comment) }
|
53
|
+
it{ should have_one_to_one(:comment).with_options :class_name => "Comment" }
|
54
|
+
it{ should_not have_one_to_one(:price) }
|
55
|
+
it{ should_not have_one_to_one(:comment).with_options :class_name => "Price" }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_format_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_format /[abc]+/, :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_format
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should require additionnal parameters" do
|
23
|
+
expect {
|
24
|
+
subject.should validate_format(:name)
|
25
|
+
}.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept with valid parameters" do
|
29
|
+
expect {
|
30
|
+
subject.should validate_format_of(:name).with(/[abc]+/)
|
31
|
+
}.not_to raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should reject with invalid parameters" do
|
35
|
+
expect {
|
36
|
+
subject.should validate_format_of(:name).with(/[xyz]+/)
|
37
|
+
}.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should accept with valid parameters and options" do
|
41
|
+
expect {
|
42
|
+
subject.should validate_format_of(:name).with(/[abc]+/).allowing_nil
|
43
|
+
}.not_to raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should reject with valid parameters but invalid options" do
|
47
|
+
expect {
|
48
|
+
subject.should validate_format_of(:name).with(/[abc]+/).allowing_missing
|
49
|
+
}.to raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "messages" do
|
53
|
+
describe "without option" do
|
54
|
+
it "should contain a description" do
|
55
|
+
@matcher = validate_format_of(:name).with(/[abc]+/)
|
56
|
+
@matcher.description.should == "validate format of :name against /[abc]+/"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set failure messages" do
|
60
|
+
@matcher = validate_format_of(:name).with(/[abc]+/)
|
61
|
+
@matcher.matches? subject
|
62
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
63
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe "with options" do
|
67
|
+
it "should contain a description" do
|
68
|
+
@matcher = validate_format_of(:name).with(/[abc]+/).allowing_nil
|
69
|
+
@matcher.description.should == "validate format of :name against /[abc]+/ with option(s) :allow_nil => true"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set failure messages" do
|
73
|
+
@matcher = validate_format_of(:price).with(/[abc]+/).allowing_nil
|
74
|
+
@matcher.matches? subject
|
75
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
76
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should explicit used options if different than expected" do
|
80
|
+
@matcher = validate_format_of(:name).with(/[abc]+/).allowing_blank
|
81
|
+
@matcher.matches? subject
|
82
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
83
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
84
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_includes_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_includes ["Joseph", "Jonathan"], :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 ensure_inclusion_of
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should require additionnal parameters" do
|
23
|
+
expect {
|
24
|
+
subject.should ensure_inclusion_of(:name)
|
25
|
+
}.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept with valid parameters" do
|
29
|
+
expect {
|
30
|
+
subject.should ensure_inclusion_of(:name).in(["Joseph", "Jonathan"])
|
31
|
+
}.not_to raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should reject with invalid parameters" do
|
35
|
+
expect {
|
36
|
+
subject.should ensure_inclusion_of(:name).in(["Adrià", "Jonathan"])
|
37
|
+
}.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should accept with valid parameters and options" do
|
41
|
+
expect {
|
42
|
+
subject.should ensure_inclusion_of(:name).in(["Joseph", "Jonathan"]).allowing_nil
|
43
|
+
}.not_to raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should reject with valid parameters but invalid options" do
|
47
|
+
expect {
|
48
|
+
subject.should ensure_inclusion_of(:name).in(["Joseph", "Jonathan"]).allowing_blank
|
49
|
+
}.to raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "messages" do
|
53
|
+
describe "without option" do
|
54
|
+
it "should contain a description" do
|
55
|
+
@matcher = ensure_inclusion_of(:name).in ["Joseph", "Jonathan"]
|
56
|
+
@matcher.description.should == 'validate that :name is included in ["Joseph", "Jonathan"]'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set failure messages" do
|
60
|
+
@matcher = ensure_inclusion_of(:name).in ["Joseph", "Jonathan"]
|
61
|
+
@matcher.matches? subject
|
62
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
63
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe "with options" do
|
67
|
+
it "should contain a description" do
|
68
|
+
@matcher = ensure_inclusion_of(:name).in(["Joseph", "Jonathan"]).allowing_nil
|
69
|
+
@matcher.description.should == 'validate that :name is included in ["Joseph", "Jonathan"] with option(s) :allow_nil => true'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set failure messages" do
|
73
|
+
@matcher = ensure_inclusion_of(:price).in(["Joseph", "Jonathan"]).allowing_nil
|
74
|
+
@matcher.matches? subject
|
75
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
76
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should explicit used options if different than expected" do
|
80
|
+
@matcher = ensure_inclusion_of(:name).in(["Joseph", "Jonathan"]).allowing_blank
|
81
|
+
@matcher.matches? subject
|
82
|
+
explanation = " but called with option(s) :allow_nil => true instead"
|
83
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
84
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "validate_integer_matcher" do
|
4
|
+
before :all do
|
5
|
+
define_model :item do
|
6
|
+
plugin :validation_helpers
|
7
|
+
|
8
|
+
def validate
|
9
|
+
validates_integer [: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_integer
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept with an attribute" do
|
23
|
+
expect {
|
24
|
+
subject.should validate_integer(:name)
|
25
|
+
}.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept with valid options" do
|
29
|
+
expect {
|
30
|
+
subject.should validate_integer(: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_integer(: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_integer :name
|
44
|
+
@matcher.description.should == "validate that :name is a valid integer"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set failure messages" do
|
48
|
+
@matcher = validate_integer :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_integer(:name).allowing_nil
|
57
|
+
@matcher.description.should == "validate that :name is a valid integer with option(s) :allow_nil => true"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set failure messages" do
|
61
|
+
@matcher = validate_integer(: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_integer(: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
|