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,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe "validate_schema_types_matcher" do
4
+ before :all do
5
+ define_model :item do
6
+ plugin :validation_helpers
7
+
8
+ def validate
9
+ validates_schema_types :name, :message => "Not a valid string"
10
+ end
11
+ end
12
+ end
13
+
14
+ subject{ Item }
15
+
16
+ it "should require an attribute" do
17
+ expect {
18
+ subject.should validate_schema_types_of
19
+ }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should accept with valid parameters" do
23
+ expect {
24
+ subject.should validate_schema_types_of(:name)
25
+ }.not_to raise_error
26
+ end
27
+
28
+ it "should reject with invalid parameters" do
29
+ expect {
30
+ subject.should validate_schema_types_of(:origin)
31
+ }.to raise_error
32
+ end
33
+
34
+ it "should accept with valid parameters and valid options" do
35
+ expect {
36
+ subject.should validate_schema_types_of(:name).with_message "Not a valid string"
37
+ }.not_to raise_error
38
+ end
39
+
40
+ it "should reject with valid parameters but invalid options" do
41
+ expect {
42
+ subject.should validate_schema_types_of(:name).allowing_blank
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_schema_types_of(:name)
50
+ @matcher.description.should == 'validate schema types of :name'
51
+ end
52
+
53
+ it "should set failure messages" do
54
+ @matcher = validate_schema_types_of(: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_schema_types_of(:name).with_message "Not a valid string"
64
+ @matcher.description.should == 'validate schema types of :name with option(s) :message => "Not a valid string"'
65
+ end
66
+
67
+ it "should set failure messages" do
68
+ @matcher = validate_schema_types_of(:username).with_message("Not a valid string")
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_schema_types_of(:name).with_message "Not a valid hash"
76
+ @matcher.matches? subject
77
+ explanation = ' but called with option(s) :message => "Not a valid string" 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,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe "validate_type_matcher" do
4
+ before :all do
5
+ define_model :item do
6
+ plugin :validation_helpers
7
+
8
+ def validate
9
+ validates_type [String, Integer], :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_type_of
19
+ }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should require additionnal parameters" do
23
+ expect {
24
+ subject.should validate_type_of(:name)
25
+ }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should accept with valid parameters" do
29
+ expect {
30
+ subject.should validate_type_of(:name).is [String, Integer]
31
+ }.not_to raise_error
32
+ end
33
+
34
+ it "should reject with invalid parameters" do
35
+ expect {
36
+ subject.should validate_type_of(:name).is [Array, Integer]
37
+ }.to raise_error
38
+ end
39
+
40
+ it "should accept with valid parameters and options" do
41
+ expect {
42
+ subject.should validate_type_of(:name).is([String, Integer]).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_type_of(:name).is([String, Integer]).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 = validate_type_of(:name).is Integer
56
+ @matcher.description.should == 'validate that type of :name is Integer'
57
+ end
58
+
59
+ it "should set failure messages" do
60
+ @matcher = validate_type_of(:name).is [String, Integer]
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_type_of(:name).is([String, Integer]).allowing_nil
69
+ @matcher.description.should == 'validate that type of :name is [String, Integer] with option(s) :allow_nil => true'
70
+ end
71
+
72
+ it "should set failure messages" do
73
+ @matcher = validate_type_of(:price).is([String, Integer]).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_type_of(:name).is([String, Integer]).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,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe "validate_unique_matcher" do
4
+ before do
5
+ define_model :item do
6
+ plugin :validation_helpers
7
+
8
+ def validate
9
+ validates_unique [:id, :name], :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_unique
19
+ }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should accept with an attribute" do
23
+ expect {
24
+ subject.should validate_unique(:name)
25
+ }.not_to raise_error
26
+ end
27
+
28
+ it "should accept with valid options" do
29
+ expect {
30
+ subject.should validate_unique(: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_unique(: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_unique(: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_unique :name
50
+ @matcher.description.should == "validate uniqueness of :name"
51
+ end
52
+
53
+ it "should set failure messages" do
54
+ @matcher = validate_unique :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_unique(:name).with_message("Hello")
64
+ @matcher.description.should == 'validate uniqueness of :name with option(s) :message => "Hello"'
65
+ end
66
+
67
+ it "should set failure messages" do
68
+ @matcher = validate_unique(: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_unique(: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,33 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'sequel'
4
+ require 'database_cleaner'
5
+ require 'sequel_spec'
6
+
7
+ require 'support/test_helpers'
8
+
9
+ DB = Sequel.connect('sqlite://test.db')
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.order = 'random'
15
+
16
+ config.before(:suite) do
17
+ DatabaseCleaner.strategy = :transaction
18
+ DatabaseCleaner.clean_with(:truncation)
19
+
20
+ Sequel.extension :migration
21
+ Sequel::Migrator.apply(DB, 'spec/migrations')
22
+ end
23
+
24
+ config.before(:each) do
25
+ DatabaseCleaner.start
26
+ end
27
+
28
+ config.after(:each) do
29
+ DatabaseCleaner.clean
30
+ end
31
+
32
+ config.include TestHelpers
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'sequel/extensions/inflector'
2
+
3
+ module TestHelpers
4
+ @@models = []
5
+
6
+ def define_model(model_name, &block)
7
+ class_name = model_name.to_s.camelize.to_sym
8
+ table_name = model_name.to_s.tableize.to_sym
9
+
10
+ if @@models.include?(model_name)
11
+ Object.send(:remove_const, class_name)
12
+ else
13
+ @@models << model_name
14
+ end
15
+
16
+ klass = Object.const_set class_name, Sequel::Model(table_name)
17
+ klass.class_eval &block if block_given?
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrià Planas
8
+ - Jonathan Tron
9
+ - Joseph Halter
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-03-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sequel
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '4.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.5'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.5'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: database_cleaner
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: sqlite3
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ description:
86
+ email:
87
+ - adriaplanas@liquidcodeworks.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - lib/sequel_spec.rb
99
+ - lib/sequel_spec/association.rb
100
+ - lib/sequel_spec/association/association_matcher.rb
101
+ - lib/sequel_spec/association/have_many_to_many_matcher.rb
102
+ - lib/sequel_spec/association/have_many_to_one_matcher.rb
103
+ - lib/sequel_spec/association/have_one_through_one_matcher.rb
104
+ - lib/sequel_spec/association/have_one_to_many_matcher.rb
105
+ - lib/sequel_spec/association/have_one_to_one_matcher.rb
106
+ - lib/sequel_spec/base.rb
107
+ - lib/sequel_spec/integration/rspec.rb
108
+ - lib/sequel_spec/validation.rb
109
+ - lib/sequel_spec/validation/validate_format_matcher.rb
110
+ - lib/sequel_spec/validation/validate_includes_matcher.rb
111
+ - lib/sequel_spec/validation/validate_integer_matcher.rb
112
+ - lib/sequel_spec/validation/validate_length_matcher.rb
113
+ - lib/sequel_spec/validation/validate_matcher.rb
114
+ - lib/sequel_spec/validation/validate_not_null_matcher.rb
115
+ - lib/sequel_spec/validation/validate_numeric_matcher.rb
116
+ - lib/sequel_spec/validation/validate_presence_matcher.rb
117
+ - lib/sequel_spec/validation/validate_schema_types_matcher.rb
118
+ - lib/sequel_spec/validation/validate_type_matcher.rb
119
+ - lib/sequel_spec/validation/validate_unique_matcher.rb
120
+ - lib/sequel_spec/version.rb
121
+ - sequel_spec.gemspec
122
+ - spec/migrations/001_create_tables.rb
123
+ - spec/sequel_spec/association/have_many_to_many_matcher_spec.rb
124
+ - spec/sequel_spec/association/have_many_to_one_matcher_spec.rb
125
+ - spec/sequel_spec/association/have_one_through_one_matcher_spec.rb
126
+ - spec/sequel_spec/association/have_one_to_many_matcher_spec.rb
127
+ - spec/sequel_spec/association/have_one_to_one_matcher_spec.rb
128
+ - spec/sequel_spec/validation/validate_format_matcher_spec.rb
129
+ - spec/sequel_spec/validation/validate_includes_matcher_spec.rb
130
+ - spec/sequel_spec/validation/validate_integer_matcher_spec.rb
131
+ - spec/sequel_spec/validation/validate_length_matcher_spec.rb
132
+ - spec/sequel_spec/validation/validate_not_null_matcher_spec.rb
133
+ - spec/sequel_spec/validation/validate_numeric_matcher_spec.rb
134
+ - spec/sequel_spec/validation/validate_presence_matcher_spec.rb
135
+ - spec/sequel_spec/validation/validate_schema_types_matcher_spec.rb
136
+ - spec/sequel_spec/validation/validate_type_matcher_spec.rb
137
+ - spec/sequel_spec/validation/validate_unique_matcher_spec.rb
138
+ - spec/spec_helper.rb
139
+ - spec/support/test_helpers.rb
140
+ homepage: https://github.com/planas/sequel_spec
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.2.2
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: RSpec Matchers for Sequel
164
+ test_files: []