JonathanTron-rspec_sequel_matchers 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +29 -4
- data/VERSION +1 -1
- data/lib/rspec_sequel/association.rb +1 -1
- data/lib/rspec_sequel/base.rb +1 -1
- data/lib/rspec_sequel/matchers/validate_exact_length.rb +2 -2
- data/lib/rspec_sequel/matchers/validate_format.rb +25 -0
- data/lib/rspec_sequel/matchers/validate_includes.rb +25 -0
- data/lib/rspec_sequel/matchers/validate_integer.rb +21 -0
- data/lib/rspec_sequel/matchers/validate_length_range.rb +25 -0
- data/lib/rspec_sequel/matchers/validate_max_length.rb +25 -0
- data/lib/rspec_sequel/matchers/validate_min_length.rb +25 -0
- data/lib/rspec_sequel/matchers/validate_not_string.rb +21 -0
- data/lib/rspec_sequel/matchers/validate_numeric.rb +21 -0
- data/lib/rspec_sequel/matchers/validate_presence.rb +1 -1
- data/lib/rspec_sequel/matchers/validate_unique.rb +33 -0
- data/lib/rspec_sequel/validation.rb +5 -1
- data/rspec_sequel_matchers.gemspec +30 -3
- data/spec/have_column_matcher_spec.rb +15 -14
- data/spec/have_many_to_many_matcher_spec.rb +8 -7
- data/spec/have_many_to_one_matcher_spec.rb +8 -7
- data/spec/have_one_to_many_matcher_spec.rb +8 -7
- data/spec/validate_exact_length_matcher_spec.rb +12 -10
- data/spec/validate_format_matcher_spec.rb +88 -0
- data/spec/validate_includes_matcher_spec.rb +88 -0
- data/spec/validate_integer_matcher_spec.rb +77 -0
- data/spec/validate_length_range_matcher_spec.rb +88 -0
- data/spec/validate_max_length_matcher_spec.rb +88 -0
- data/spec/validate_min_length_matcher_spec.rb +88 -0
- data/spec/validate_not_string_matcher_spec.rb +77 -0
- data/spec/validate_numeric_matcher_spec.rb +77 -0
- data/spec/validate_presence_matcher_spec.rb +11 -9
- data/spec/validate_unique_matcher_spec.rb +79 -0
- metadata +28 -1
data/README.rdoc
CHANGED
@@ -1,9 +1,34 @@
|
|
1
1
|
= rspec_sequel_matchers
|
2
2
|
|
3
|
-
Some Sequel Matchers for RSpec, using no other gem than rspec and sequel themself.
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
Some Sequel Matchers for RSpec, using no other gem than rspec and sequel themself. As a consequence, you can use these matchers with Rails, Sinatra or any other framework. It's pretty feature complete.
|
4
|
+
|
5
|
+
Matchers assume that you're using the recommanded validation_helpers plugin. All instance validation methods are supported, namely:
|
6
|
+
* validates_exact_length
|
7
|
+
* validates_format
|
8
|
+
* validates_includes
|
9
|
+
* validates_integer
|
10
|
+
* validates_length_range
|
11
|
+
* validates_max_length
|
12
|
+
* validates_min_length
|
13
|
+
* validates_not_string
|
14
|
+
* validates_numeric
|
15
|
+
* validates_presence
|
16
|
+
* validates_unique
|
17
|
+
|
18
|
+
Each one with all possible options, namely:
|
19
|
+
* :allow_blank
|
20
|
+
* :allow_missing
|
21
|
+
* :allow_nil
|
22
|
+
* :message
|
23
|
+
|
24
|
+
There're also matchers for associations class methods:
|
25
|
+
* :many_to_many
|
26
|
+
* :many_to_one
|
27
|
+
* :one_to_many
|
28
|
+
|
29
|
+
And there's an additionnal matcher have_column to check columns existance and their type, see example usage bellow.
|
30
|
+
|
31
|
+
RspecSequel::Matchers has an extensive test suite and will give you as much explanation as possible in failure messages such as expected column type versus column type found in database.
|
7
32
|
|
8
33
|
== Install
|
9
34
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -4,7 +4,7 @@ module RspecSequel
|
|
4
4
|
|
5
5
|
def description
|
6
6
|
desc = "have a #{association_type} association #{@attribute.inspect}"
|
7
|
-
desc << " with #{hash_to_nice_string @options}" unless @options.empty?
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
8
|
desc
|
9
9
|
end
|
10
10
|
|
data/lib/rspec_sequel/base.rb
CHANGED
@@ -3,7 +3,7 @@ module RspecSequel
|
|
3
3
|
class Base
|
4
4
|
def initialize(attribute, options={})
|
5
5
|
raise ArgumentError, "not enough params for matcher, required attribute is missing" if attribute.nil?
|
6
|
-
@attribute = attribute
|
6
|
+
@attribute = attribute
|
7
7
|
@options = options
|
8
8
|
@description = []
|
9
9
|
end
|
@@ -3,8 +3,8 @@ module RspecSequel
|
|
3
3
|
|
4
4
|
class ValidateExactLengthMatcher < RspecSequel::Validation
|
5
5
|
def description
|
6
|
-
desc = "validate
|
7
|
-
desc << " with #{hash_to_nice_string @options}" unless @options.empty?
|
6
|
+
desc = "validate length of #{@attribute.inspect} is exactly #{@additionnal.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
8
|
desc
|
9
9
|
end
|
10
10
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateFormatMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate format of #{@attribute.inspect} against #{@additionnal.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def additionnal_param_type
|
12
|
+
Regexp
|
13
|
+
end
|
14
|
+
|
15
|
+
def validation_type
|
16
|
+
:validates_format
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_format(*args)
|
21
|
+
ValidateFormatMatcher.new(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateIncludesMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate that #{@attribute.inspect} is included in #{@additionnal.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def additionnal_param_type
|
12
|
+
Enumerable
|
13
|
+
end
|
14
|
+
|
15
|
+
def validation_type
|
16
|
+
:validates_includes
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_includes(*args)
|
21
|
+
ValidateIncludesMatcher.new(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateIntegerMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate that #{@attribute.inspect} is a valid integer"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def validation_type
|
12
|
+
:validates_integer
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate_integer(*args)
|
17
|
+
ValidateIntegerMatcher.new(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateLengthRangeMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate length of #{@attribute.inspect} is included in #{@additionnal.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def additionnal_param_type
|
12
|
+
Enumerable
|
13
|
+
end
|
14
|
+
|
15
|
+
def validation_type
|
16
|
+
:validates_length_range
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_length_range(*args)
|
21
|
+
ValidateLengthRangeMatcher.new(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateMaxLengthMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate length of #{@attribute.inspect} is less than or equal to #{@additionnal.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def additionnal_param_type
|
12
|
+
Fixnum
|
13
|
+
end
|
14
|
+
|
15
|
+
def validation_type
|
16
|
+
:validates_max_length
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_max_length(*args)
|
21
|
+
ValidateMaxLengthMatcher.new(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateMinLengthMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate length of #{@attribute.inspect} is greater than or equal to #{@additionnal.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def additionnal_param_type
|
12
|
+
Fixnum
|
13
|
+
end
|
14
|
+
|
15
|
+
def validation_type
|
16
|
+
:validates_min_length
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_min_length(*args)
|
21
|
+
ValidateMinLengthMatcher.new(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateNotStringMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate that #{@attribute.inspect} is not a string"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def validation_type
|
12
|
+
:validates_not_string
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate_not_string(*args)
|
17
|
+
ValidateNotStringMatcher.new(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateNumericMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate that #{@attribute.inspect} is a valid float"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def validation_type
|
12
|
+
:validates_numeric
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate_numeric(*args)
|
17
|
+
ValidateNumericMatcher.new(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -4,7 +4,7 @@ module RspecSequel
|
|
4
4
|
class ValidatePresenceMatcher < RspecSequel::Validation
|
5
5
|
def description
|
6
6
|
desc = "validate presence of #{@attribute.inspect}"
|
7
|
-
desc << " with #{hash_to_nice_string @options}" unless @options.empty?
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
8
|
desc
|
9
9
|
end
|
10
10
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RspecSequel
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ValidateUniqueMatcher < RspecSequel::Validation
|
5
|
+
def description
|
6
|
+
desc = "validate uniqueness of #{@attribute.inspect}"
|
7
|
+
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
|
8
|
+
desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def validation_type
|
12
|
+
:validates_unique
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_options
|
16
|
+
[:message]
|
17
|
+
end
|
18
|
+
|
19
|
+
def args_to_called_attributes(args)
|
20
|
+
called_attributes = []
|
21
|
+
until args.empty?
|
22
|
+
called_attributes << args.shift
|
23
|
+
end
|
24
|
+
called_attributes
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate_unique(*args)
|
29
|
+
ValidateUniqueMatcher.new(*args)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -46,7 +46,7 @@ module RspecSequel
|
|
46
46
|
i.class.columns # ensure colums are read again after .dup
|
47
47
|
i.stub!(validation_type).and_return{|*args|
|
48
48
|
called_options = args.last.is_a?(Hash) ? args.pop : {}
|
49
|
-
called_attributes =
|
49
|
+
called_attributes = args_to_called_attributes(args)
|
50
50
|
called_additionnal = args.shift if additionnal_param_required?
|
51
51
|
if !args.empty?
|
52
52
|
@suffix << "but called with too many params"
|
@@ -67,6 +67,10 @@ module RspecSequel
|
|
67
67
|
end
|
68
68
|
called_count==1
|
69
69
|
end
|
70
|
+
|
71
|
+
def args_to_called_attributes(args)
|
72
|
+
[args.pop].flatten
|
73
|
+
end
|
70
74
|
|
71
75
|
end
|
72
76
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rspec_sequel_matchers}
|
5
|
-
s.version = "0.0
|
5
|
+
s.version = "0.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jonathan Tron", "Joseph Halter"]
|
@@ -26,7 +26,16 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/rspec_sequel/matchers/have_many_to_one.rb",
|
27
27
|
"lib/rspec_sequel/matchers/have_one_to_many.rb",
|
28
28
|
"lib/rspec_sequel/matchers/validate_exact_length.rb",
|
29
|
+
"lib/rspec_sequel/matchers/validate_format.rb",
|
30
|
+
"lib/rspec_sequel/matchers/validate_includes.rb",
|
31
|
+
"lib/rspec_sequel/matchers/validate_integer.rb",
|
32
|
+
"lib/rspec_sequel/matchers/validate_length_range.rb",
|
33
|
+
"lib/rspec_sequel/matchers/validate_max_length.rb",
|
34
|
+
"lib/rspec_sequel/matchers/validate_min_length.rb",
|
35
|
+
"lib/rspec_sequel/matchers/validate_not_string.rb",
|
36
|
+
"lib/rspec_sequel/matchers/validate_numeric.rb",
|
29
37
|
"lib/rspec_sequel/matchers/validate_presence.rb",
|
38
|
+
"lib/rspec_sequel/matchers/validate_unique.rb",
|
30
39
|
"lib/rspec_sequel/validation.rb",
|
31
40
|
"lib/rspec_sequel_matchers.rb",
|
32
41
|
"rspec_sequel_matchers.gemspec",
|
@@ -39,7 +48,16 @@ Gem::Specification.new do |s|
|
|
39
48
|
"spec/migrations/003_create_comments_items.rb",
|
40
49
|
"spec/spec_helper.rb",
|
41
50
|
"spec/validate_exact_length_matcher_spec.rb",
|
42
|
-
"spec/
|
51
|
+
"spec/validate_format_matcher_spec.rb",
|
52
|
+
"spec/validate_includes_matcher_spec.rb",
|
53
|
+
"spec/validate_integer_matcher_spec.rb",
|
54
|
+
"spec/validate_length_range_matcher_spec.rb",
|
55
|
+
"spec/validate_max_length_matcher_spec.rb",
|
56
|
+
"spec/validate_min_length_matcher_spec.rb",
|
57
|
+
"spec/validate_not_string_matcher_spec.rb",
|
58
|
+
"spec/validate_numeric_matcher_spec.rb",
|
59
|
+
"spec/validate_presence_matcher_spec.rb",
|
60
|
+
"spec/validate_unique_matcher_spec.rb"
|
43
61
|
]
|
44
62
|
s.has_rdoc = true
|
45
63
|
s.homepage = %q{http://github.com/JonathanTron/rspec_sequel_matchers}
|
@@ -57,7 +75,16 @@ Gem::Specification.new do |s|
|
|
57
75
|
"spec/migrations/003_create_comments_items.rb",
|
58
76
|
"spec/spec_helper.rb",
|
59
77
|
"spec/validate_exact_length_matcher_spec.rb",
|
60
|
-
"spec/
|
78
|
+
"spec/validate_format_matcher_spec.rb",
|
79
|
+
"spec/validate_includes_matcher_spec.rb",
|
80
|
+
"spec/validate_integer_matcher_spec.rb",
|
81
|
+
"spec/validate_length_range_matcher_spec.rb",
|
82
|
+
"spec/validate_max_length_matcher_spec.rb",
|
83
|
+
"spec/validate_min_length_matcher_spec.rb",
|
84
|
+
"spec/validate_not_string_matcher_spec.rb",
|
85
|
+
"spec/validate_numeric_matcher_spec.rb",
|
86
|
+
"spec/validate_presence_matcher_spec.rb",
|
87
|
+
"spec/validate_unique_matcher_spec.rb"
|
61
88
|
]
|
62
89
|
|
63
90
|
if s.respond_to? :specification_version then
|
@@ -17,8 +17,8 @@ describe "have_column_matcher" do
|
|
17
17
|
it "should set failure messages" do
|
18
18
|
@matcher = have_column :name
|
19
19
|
@matcher.matches? subject
|
20
|
-
@matcher.failure_message.should == "expected Item to
|
21
|
-
@matcher.negative_failure_message.should ==
|
20
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
21
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
22
22
|
end
|
23
23
|
end
|
24
24
|
describe "with type as symbol" do
|
@@ -29,8 +29,8 @@ describe "have_column_matcher" do
|
|
29
29
|
it "should set failure messages" do
|
30
30
|
@matcher = have_column :password, :type => :string
|
31
31
|
@matcher.matches? subject
|
32
|
-
@matcher.failure_message.should == "expected Item to
|
33
|
-
@matcher.negative_failure_message.should ==
|
32
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
33
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
34
34
|
end
|
35
35
|
end
|
36
36
|
describe "with type as object" do
|
@@ -41,38 +41,39 @@ describe "have_column_matcher" do
|
|
41
41
|
it "should set failure messages" do
|
42
42
|
@matcher = have_column :password, :type => String
|
43
43
|
@matcher.matches? subject
|
44
|
-
@matcher.failure_message.should == "expected Item to
|
45
|
-
@matcher.negative_failure_message.should ==
|
44
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
45
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
46
46
|
end
|
47
47
|
it "should explicit found type if different than expected" do
|
48
48
|
@matcher = have_column :name, :type => Integer
|
49
49
|
@matcher.matches? subject
|
50
|
-
|
51
|
-
@matcher.
|
50
|
+
explanation = " (type found: string, varchar(255))"
|
51
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
|
52
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
|
52
53
|
end
|
53
54
|
end
|
54
55
|
describe "on anonymous Sequel::Model class" do
|
55
56
|
it "should set failure messages" do
|
56
57
|
@matcher = have_column :password
|
57
58
|
@matcher.matches? Sequel::Model(:comments)
|
58
|
-
@matcher.failure_message.should == "expected comments to
|
59
|
-
@matcher.negative_failure_message.should ==
|
59
|
+
@matcher.failure_message.should == "expected comments to " + @matcher.description
|
60
|
+
@matcher.negative_failure_message.should == "expected comments to not " + @matcher.description
|
60
61
|
end
|
61
62
|
end
|
62
63
|
describe "on Sequel::Model class" do
|
63
64
|
it "should set failure messages" do
|
64
65
|
@matcher = have_column :password
|
65
66
|
@matcher.matches? Item
|
66
|
-
@matcher.failure_message.should == "expected Item to
|
67
|
-
@matcher.negative_failure_message.should ==
|
67
|
+
@matcher.failure_message.should == "expected Item to " + @matcher.description
|
68
|
+
@matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
|
68
69
|
end
|
69
70
|
end
|
70
71
|
describe "on Sequel::Model instance" do
|
71
72
|
it "should set failure messages" do
|
72
73
|
@matcher = have_column :password
|
73
74
|
@matcher.matches? Item.new
|
74
|
-
@matcher.failure_message.should == "expected #<Item @values={}> to
|
75
|
-
@matcher.negative_failure_message.should ==
|
75
|
+
@matcher.failure_message.should == "expected #<Item @values={}> to " + @matcher.description
|
76
|
+
@matcher.negative_failure_message.should == "expected #<Item @values={}> to not " + @matcher.description
|
76
77
|
end
|
77
78
|
end
|
78
79
|
end
|