sequel_spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +22 -0
  6. data/README.md +91 -0
  7. data/Rakefile +1 -0
  8. data/lib/sequel_spec.rb +8 -0
  9. data/lib/sequel_spec/association.rb +13 -0
  10. data/lib/sequel_spec/association/association_matcher.rb +32 -0
  11. data/lib/sequel_spec/association/have_many_to_many_matcher.rb +15 -0
  12. data/lib/sequel_spec/association/have_many_to_one_matcher.rb +15 -0
  13. data/lib/sequel_spec/association/have_one_through_one_matcher.rb +15 -0
  14. data/lib/sequel_spec/association/have_one_to_many_matcher.rb +15 -0
  15. data/lib/sequel_spec/association/have_one_to_one_matcher.rb +15 -0
  16. data/lib/sequel_spec/base.rb +45 -0
  17. data/lib/sequel_spec/integration/rspec.rb +6 -0
  18. data/lib/sequel_spec/validation.rb +18 -0
  19. data/lib/sequel_spec/validation/validate_format_matcher.rb +42 -0
  20. data/lib/sequel_spec/validation/validate_includes_matcher.rb +43 -0
  21. data/lib/sequel_spec/validation/validate_integer_matcher.rb +23 -0
  22. data/lib/sequel_spec/validation/validate_length_matcher.rb +81 -0
  23. data/lib/sequel_spec/validation/validate_matcher.rb +67 -0
  24. data/lib/sequel_spec/validation/validate_not_null_matcher.rb +21 -0
  25. data/lib/sequel_spec/validation/validate_numeric_matcher.rb +23 -0
  26. data/lib/sequel_spec/validation/validate_presence_matcher.rb +23 -0
  27. data/lib/sequel_spec/validation/validate_schema_types_matcher.rb +23 -0
  28. data/lib/sequel_spec/validation/validate_type_matcher.rb +42 -0
  29. data/lib/sequel_spec/validation/validate_unique_matcher.rb +31 -0
  30. data/lib/sequel_spec/version.rb +3 -0
  31. data/sequel_spec.gemspec +25 -0
  32. data/spec/migrations/001_create_tables.rb +26 -0
  33. data/spec/sequel_spec/association/have_many_to_many_matcher_spec.rb +57 -0
  34. data/spec/sequel_spec/association/have_many_to_one_matcher_spec.rb +57 -0
  35. data/spec/sequel_spec/association/have_one_through_one_matcher_spec.rb +57 -0
  36. data/spec/sequel_spec/association/have_one_to_many_matcher_spec.rb +57 -0
  37. data/spec/sequel_spec/association/have_one_to_one_matcher_spec.rb +57 -0
  38. data/spec/sequel_spec/validation/validate_format_matcher_spec.rb +88 -0
  39. data/spec/sequel_spec/validation/validate_includes_matcher_spec.rb +88 -0
  40. data/spec/sequel_spec/validation/validate_integer_matcher_spec.rb +76 -0
  41. data/spec/sequel_spec/validation/validate_length_matcher_spec.rb +252 -0
  42. data/spec/sequel_spec/validation/validate_not_null_matcher_spec.rb +83 -0
  43. data/spec/sequel_spec/validation/validate_numeric_matcher_spec.rb +76 -0
  44. data/spec/sequel_spec/validation/validate_presence_matcher_spec.rb +77 -0
  45. data/spec/sequel_spec/validation/validate_schema_types_matcher_spec.rb +83 -0
  46. data/spec/sequel_spec/validation/validate_type_matcher_spec.rb +88 -0
  47. data/spec/sequel_spec/validation/validate_unique_matcher_spec.rb +83 -0
  48. data/spec/spec_helper.rb +33 -0
  49. data/spec/support/test_helpers.rb +19 -0
  50. 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