ratatouille 0.1.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Ratatouille [![Build Status](http://travis-ci.org/CITguy/ratatouille.png)](http://travis-ci.org/CITguy/ratatouille)
1
+ # Ratatouille
2
2
 
3
- DSL for validation of complex Hashes
3
+ TODO: Write a gem description
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,229 +16,9 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install ratatouille
18
18
 
19
-
20
-
21
- ## Blocks
22
-
23
- All of the given methods accept a block for validation and will not progress into the block if the core method logic does not validate.
24
- However, some methods may be used without a block and validation will progress whether or not the method logic validates.
25
-
26
-
27
- ### ratifiable\_object
28
-
29
- Within a block, the ratifiable\_object method provides the object that is to be validated against.
30
- This will change when using *given\_key*.
31
-
32
-
33
-
34
19
  ## Usage
35
20
 
36
- All of the following methods perform validation on the *ratifiable\_object* defined in scope of the block.
37
-
38
-
39
- ### given\_key
40
-
41
- This method is used to scope its given block to the key value. Useful to reduce the need to explicitly namespace nested keys in *ratifiable\_object*.
42
-
43
- * **This method doesn't perform any validation and must be used with a block to get any use out of it.**
44
- * Changes *ratifiable\_object* to *key value* (original scope will return on block exit)
45
-
46
-
47
- #### Syntax
48
-
49
- ```ruby
50
- given_key(:foo) do
51
- # validation for ratifiable_object[:foo]
52
- end
53
- ```
54
-
55
- #### Example
56
-
57
- See **choice\_of** for an example.
58
-
59
-
60
- ### choice\_of
61
-
62
- Meant to be used to validate that X number of given key choices exist in the Hash.
63
-
64
- * Number of Choices must be less than size of key choice array
65
- * Can be used without a block
66
- * Works well with **given\_key()**.
67
-
68
-
69
- #### Syntax
70
-
71
- ```ruby
72
- choice_of(number_of_choices, key_choice_array) do
73
- # Validation provided number of choices is satisfied
74
- end
75
- ```
76
-
77
-
78
- #### Example
79
-
80
- ```ruby
81
- r = ratify({:foo => "bar", :bar => "biz"}) do
82
- choice_of(1, :foo, :bar) do
83
- # Validation, provided :foo OR :bar exists
84
- end
85
- end
86
- r.valid? #=> false (:foo OR :bar must be defined, NOT BOTH)
87
-
88
- r = ratify({:foo => "bar", :bar => "biz"}) do
89
- choice_of(2, :foo, :bar, :biz) do
90
- # Validation, provided 2 of the following exist: :foo, :bar, :biz
91
-
92
- given_key(:foo) do
93
- # in context of ratifiable_object[:foo]
94
- end
95
-
96
- given_key(:bar) do
97
- # in context of ratifiable_object[:bar]
98
- end
99
- end
100
- end
101
- r.valid? #=> true (a choice of 2 items from [:foo, :bar, :biz] is satisfied)
102
-
103
- r = ratify({:foo => "bar", :bar => "biz"}) do
104
- choice_of(2, :foo, :bar) do
105
- # Validation ...
106
- end
107
- end
108
- r.valid? #=> false (you might as well use required_keys)
109
- ```
110
-
111
-
112
- ### required\_keys
113
-
114
- Used to ensure that the list of keys exist in the Hash.
115
-
116
- * Block is optional
117
-
118
-
119
- #### Syntax
120
-
121
- ```ruby
122
- # Validate that the keys exist and perform validation if they do
123
- required_keys(:foo, :bar) do
124
- # Validation provided that :foo and :bar exist
125
- end
126
-
127
- # Validate that the keys exist
128
- required_keys(:foo, :bar)
129
- ```
130
-
131
-
132
- #### Example
133
-
134
- ```ruby
135
- r = ratify({:foo => "bar", :bar => "biz"}) do
136
- required_keys(:foo, :bar)
137
- end
138
- r.valid? #=> true
139
-
140
- r = ratify({:foo => "bar"}) do
141
- required_keys(:foo, :bar)
142
- end
143
- r.valid? #=> false
144
- ```
145
-
146
-
147
-
148
- ### is\_empty
149
-
150
- * Self-explanatory
151
- * Block is optional
152
-
153
- ```ruby
154
- r = ratify({:foo => "bar"}) do
155
- is_empty # validation continues
156
- is_empty do
157
- # validation in block is never performed
158
- end
159
- end
160
- r.valid? #=> false
161
-
162
- r = ratify({}) do
163
- is_empty # validation continues even if not empty
164
- is_empty do
165
- # validation continues only if ratifiable_object is empty
166
- end
167
- end
168
- r.valid? #=> true
169
- ```
170
-
171
-
172
- ### is\_not\_empty
173
-
174
- * Self-explanatory
175
- * Block is optional
176
-
177
- ```ruby
178
- r = ratify({:foo => "bar"}) do
179
- is_not_empty # validation continues even if empty
180
- is_not_empty do
181
- # validation continues unless ratifiable_object is empty
182
- end
183
- end
184
- r.valid? #=> true
185
-
186
- r = ratify({}) do
187
- is_not_empty # validation continues
188
- is_not_empty do
189
- # validation in block is never performed
190
- end
191
- end
192
- r.valid? #=> false
193
- ```
194
-
195
-
196
-
197
- ## Custom Validation
198
-
199
- **Return to this section after reading the remaining sections.**
200
-
201
- Custom validation can take place using the following methods to generate custom validation logic that cannot be satisfied with the existing methods.
202
-
203
- You should use the **validation\_error** method to add your own errors to the Ratifier object.
204
-
205
-
206
- ### validation\_error
207
-
208
- Used to insert validation error message into the Ratifier object.
209
-
210
-
211
- #### Syntax
212
-
213
- It is also possible to set the context of an error by passing in a second argument. However, it defaults to the root of the current ratifiable\_object ('/').
214
-
215
- ```ruby
216
- validation_error("This is an error")
217
- validation_error("This is an error", "current_context")
218
- ```
219
-
220
-
221
-
222
- ## Advanced Example
223
-
224
- ```ruby
225
- include Ratatouille
226
- r = ratify({:foo => {:bar => {:biz => "bang"}}}) do
227
- is_not_empty
228
- given_key(:foo) do
229
- validation_error(":foo error")
230
- given_key(:bar) do
231
- validation_error(":bar error")
232
- given_key(:biz) do
233
- if ratifiable_object == "bang"
234
- validation_error("should be 'shoot'")
235
- end
236
- end
237
- end
238
- end
239
- end
240
- r.valid? # => false
241
- ```
21
+ TODO: Write usage instructions here
242
22
 
243
23
  ## Contributing
244
24
 
@@ -1,6 +1,5 @@
1
1
  module Ratatouille
2
2
 
3
- # Module used to provide Array-specific validation methods
4
3
  module ArrayMethods
5
4
  # @return [void]
6
5
  def is_empty(&block)
@@ -29,11 +28,17 @@ module Ratatouille
29
28
  # @param [Integer] min_size
30
29
  # @return [void]
31
30
  def min_length(min_size=0, &block)
32
- return unless valid_min_length?(min_size)
31
+ unless min_size =~ /\d+/
32
+ validation_error("min_length argument must be an Integer")
33
+ return
34
+ end
35
+
36
+ unless @ratifiable_object.size >= min_size
37
+ validation_error("Array length must be #{size} or more")
38
+ return
39
+ end
33
40
 
34
41
  instance_eval(&block) if block_given?
35
- rescue Exception => e
36
- validation_error("#{e.message}")
37
42
  end#min_length
38
43
 
39
44
 
@@ -42,11 +47,17 @@ module Ratatouille
42
47
  # @param [Integer] min_size
43
48
  # @return [void]
44
49
  def max_length(max_size=0, &block)
45
- return unless valid_max_length?(max_size)
50
+ unless max_size =~ /\d+/
51
+ validation_error("max_length argument must be an Integer")
52
+ return
53
+ end
54
+
55
+ if @ratifiable_object.size > max_size
56
+ validation_error("Array length must be less than #{size}")
57
+ return
58
+ end
46
59
 
47
60
  instance_eval(&block) if block_given?
48
- rescue Exception => e
49
- validation_error("#{e.message}")
50
61
  end#max_length
51
62
 
52
63
 
@@ -56,65 +67,36 @@ module Ratatouille
56
67
  # @param [Integer] max_size
57
68
  # @return [void]
58
69
  def length_between(min_size=0, max_size=nil, &block)
59
- return unless valid_min_length?(min_size)
70
+ unless min_size =~ /\d+/
71
+ validation_error("min_size must be an integer")
72
+ return
73
+ end
60
74
 
61
- if max_size.nil?
62
- if min_size == 1
63
- validation_error("Consider using is_not_empty")
75
+ array_size = @ratifiable_object.size
76
+ unless array_size >= min_size
77
+ validation_error("Array length must be #{min_size} or more")
78
+ return
79
+ end
80
+
81
+ unless max_size.nil?
82
+ unless max_size =~ /\d+/
83
+ validation_error("max_size must be an integer")
64
84
  return
65
85
  end
66
- else
67
- return unless valid_max_length?(max_size)
68
86
 
69
- if max_size == 0 && min_size == 0
70
- validation_error("Consider using is_empty")
87
+ unless max_size >= min_size
88
+ validation_error("max_size must be greater than or equal to min_size")
71
89
  return
72
90
  end
73
91
 
74
- unless max_size > min_size
75
- validation_error("max_size must be greater than min_size")
92
+ unless array_size <= max_size
93
+ validation_error("Array length must be #{max_size} or less")
76
94
  return
77
95
  end
78
96
  end
79
97
 
80
98
  instance_eval(&block) if block_given?
81
99
  end#length_between
82
- private
83
-
84
- # @return [Boolean]
85
- def valid_min_length?(min_size)
86
- unless min_size.to_i >= 0
87
- validation_error("min_length must be a number greater than or equal to 0")
88
- return false
89
- end
90
-
91
- unless @ratifiable_object.size >= min_size.to_i
92
- validation_error("Array length must be #{min_size} or more")
93
- return false
94
- end
95
- return true
96
- rescue Exception => e
97
- validation_error("#{e.message}")
98
- return false
99
- end
100
-
101
- # @return [Boolean]
102
- def valid_max_length?(max_size)
103
- unless max_size.to_i >= 0
104
- validation_error("max_size must be a number greater than or equal to 0")
105
- return false
106
- end
107
-
108
- if @ratifiable_object.size > max_size.to_i
109
- validation_error("Array length must be less than #{max_size.to_i}")
110
- return false
111
- end
112
-
113
- return true
114
- rescue Exception => e
115
- validation_error("#{e.message}")
116
- return false
117
- end
118
100
  end#ArrayMethods
119
101
 
120
102
  end
@@ -1,12 +1,11 @@
1
1
  module Ratatouille
2
2
 
3
- # Module used to provide Hash-specific validation methods
4
3
  module HashMethods
5
4
  # Runs validation in block against object for the given key.
6
5
  #
7
6
  # @param [String, Symbol] key
8
7
  def given_key(key, &block)
9
- if @ratifiable_object.has_key?(key) && block_given?
8
+ if @ratifiable_object.has_key?(key)
10
9
  child_object = Ratatouille::Ratifier.new(@ratifiable_object[key], &block)
11
10
  @errors[key] = child_object.errors unless child_object.valid?
12
11
  end
@@ -38,28 +37,17 @@ module Ratatouille
38
37
  # Provide a list of keys that must be present in the Hash to validate. Otherwise,
39
38
  # an error will be added.
40
39
  #
41
- # @param [Array] args Array required keys
40
+ # @param [Array] args Array of symbols and/or strings to denote the required keys
42
41
  # @return [void]
43
- def required_keys(*req_keys, &block)
42
+ def required_keys(*args, &block)
43
+ req_keys = args.collect{|a| String === a || Symbol === a}
44
44
  common_keys = (@ratifiable_object.keys & req_keys)
45
45
 
46
- if @ratifiable_object.empty?
47
- validation_error("Cannot find required keys in empty hash.")
48
- return
49
- end
50
-
51
- if req_keys.nil? || req_keys.empty?
52
- validation_error("No required keys given to compare Hash against.")
53
- return
54
- end
55
-
56
46
  unless common_keys.size == req_keys.size
57
47
  (req_keys - common_keys).each do |missed|
58
48
  case missed
59
49
  when Symbol then validation_error("Missing :#{missed}")
60
50
  when String then validation_error("Missing #{missed}")
61
- when respond_to?(:to_s)
62
- validation_error("Missing #{missed.to_s}")
63
51
  end
64
52
  end
65
53
  return
@@ -79,18 +67,8 @@ module Ratatouille
79
67
  # All other values are ignored.
80
68
  # @return [void]
81
69
  def choice_of(choice_size=1, *key_list, &block)
82
- unless key_list.nil? || key_list.empty?
83
- validation_error("choice_of requires a key list to choose from")
84
- return
85
- end
86
-
87
70
  unless choice_size =~ /\d+/ && choice_size > 0
88
- validation_error("choice_of requires a positive integer for choice size")
89
- return
90
- end
91
-
92
- unless key_list.size > choice_size
93
- validation_error("Key list size for 'choice_of' should be larger than choice size. Consider using required_keys instead.")
71
+ validation_error("choice_of requires a positive integer as first argument")
94
72
  return
95
73
  end
96
74
 
@@ -1,6 +1,7 @@
1
- # MonkeyPatch NilClass to return true for empty?
2
- class NilClass
3
- def empty?
4
- return true
1
+ module Ratatouille
2
+ class ::NilClass
3
+ def empty?
4
+ return true
5
+ end
5
6
  end
6
7
  end
@@ -16,7 +16,7 @@ module Ratatouille
16
16
  when Array then extend Ratatouille::ArrayMethods
17
17
  end
18
18
 
19
- instance_eval( &block ) if block_given?
19
+ instance_eval(&block) if block_given?
20
20
 
21
21
  cleanup_errors
22
22
 
@@ -28,13 +28,11 @@ module Ratatouille
28
28
  # @param [String] str
29
29
  # @param [String] context
30
30
  # @return [void]
31
- def validation_error(err_in, context="/")
32
- case err_in
33
- when String
34
- return if err_in.blank?
35
- @errors[context] = [] unless @errors[context]
36
- @errors[context] << err_in
37
- end
31
+ def validation_error(str="", context="/")
32
+ return unless str.respond_to?(:to_s)
33
+ return if str.to_s.chomp == ''
34
+ @errors[context] = [] unless @errors[context]
35
+ @errors[context] << str.to_s
38
36
  rescue Exception => e
39
37
  @errors["/"] << e.message
40
38
  end#validation_error
@@ -52,7 +50,9 @@ module Ratatouille
52
50
  #
53
51
  # @return [void]
54
52
  def cleanup_errors
55
- @errors = {} if errors_array.empty?
53
+ if errors_array.empty?
54
+ @errors = {}
55
+ end
56
56
  rescue Exception => e
57
57
  @errors["/"] << e.message
58
58
  end#cleanup_errors
@@ -1,4 +1,3 @@
1
1
  module Ratatouille
2
- # Gem Version
3
- VERSION = "0.1.0"
2
+ VERSION = "0.9.2"
4
3
  end
data/lib/ratatouille.rb CHANGED
@@ -4,9 +4,7 @@ require "ratatouille/ratifier"
4
4
  require "ratatouille/nilclass"
5
5
  require "ratatouille/hash"
6
6
  require "ratatouille/array"
7
- require "ratatouille/string"
8
7
 
9
- # Module to provide DSL for validation of complex Hashes
10
8
  module Ratatouille
11
9
 
12
10
  # @param [Hash, Array] obj Object to validate
@@ -1,12 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ratatouille::Ratifier do
4
-
5
- it "should be valid on instantiation of new object" do
6
- e = RatifierTest.new({})
7
- e.should be_valid
8
- end
3
+ class RatifierTest < Ratatouille::Ratifier; end
9
4
 
5
+ describe Ratatouille::Ratifier do
10
6
  it "errors should contain one key within block of new instance" do
11
7
  x = {}
12
8
  e = RatifierTest.new({}){ x = @errors }
@@ -1,18 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
- include Ratatouille
3
+ class RatifierTest < Ratatouille::Ratifier; end
4
4
 
5
5
  describe Ratatouille do
6
6
 
7
- describe "ratify" do
8
- it "should return a Ratatouille::Ratifier object" do
9
- ratify({}).should be_a Ratatouille::Ratifier
7
+ describe "with Hash" do
8
+ describe "is_empty" do
9
+ it "should not be valid for non-empty Hash" do
10
+ e = RatifierTest.new({:bar => 'biz'}){ is_empty }
11
+ #puts "RatifierTest:"
12
+ #puts "@ratifiable_object.nil? #{e.ratifiable_object.nil?}"
13
+ #puts e.ratifiable_object.inspect
14
+ #puts "Errors.nil? #{e.errors.nil?}"
15
+ #puts e.errors.inspect
16
+ #puts "Errors.empty? #{e.errors.empty?}"
17
+ #puts "Valid?: #{e.valid?}"
18
+ e.valid?.should be_false
19
+ end
20
+
21
+ it "should be valid for empty Hash" do
22
+ e = RatifierTest.new({}){ is_empty }
23
+ e.valid?.should be_true
24
+ end
25
+ end
26
+
27
+ describe "is_not_empty" do
28
+ it "should be valid for non-empty hash" do
29
+ e = RatifierTest.new({:bar => "biz"}){ is_not_empty }
30
+ e.valid?.should be_true
31
+ end
32
+
33
+ it "should not be valid for empty hash" do
34
+ e = RatifierTest.new({}){ is_not_empty }
35
+ e.valid?.should be_false
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "with Array" do
41
+ describe "is_empty" do
42
+ it "should not be valid for non-empty array" do
43
+ e = RatifierTest.new(['bar']){ is_empty }
44
+ e.valid?.should be_false
45
+ end
46
+
47
+ it "should be valid for empty array" do
48
+ e = RatifierTest.new([]){ is_empty }
49
+ e.valid?.should be_true
50
+ end
10
51
  end
52
+
53
+ describe "is_not_empty" do
54
+ it "should be valid for non-empty array" do
55
+ e = RatifierTest.new(['bar']){ is_not_empty }
56
+ e.valid?.should be_true
57
+ end
11
58
 
12
- it "should evaluate block in context of a Ratatouille::Ratifier object" do
13
- o = nil
14
- ratify({}) { o = self }
15
- o.should be_a Ratatouille::Ratifier
59
+ it "should not be valid for empty array" do
60
+ e = RatifierTest.new([]){ is_not_empty }
61
+ e.valid?.should be_false
62
+ end
16
63
  end
17
64
  end
18
65
 
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ class TestRatifier < Ratatouille::Ratifier; end
4
+
5
+ describe Ratatouille::Ratifier do
6
+ it "should be valid upon instantiation without a block" do
7
+ r = TestRatifier.new({})
8
+ r.valid?.should be_true
9
+ end
10
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,3 @@ require 'ratatouille'
4
4
  RSpec.configure do |config|
5
5
  config.color_enabled = true
6
6
  end
7
-
8
- class RatifierTest < Ratatouille::Ratifier
9
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratatouille
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
8
+ - 9
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Johnson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-14 00:00:00 Z
18
+ date: 2012-04-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -70,14 +70,11 @@ files:
70
70
  - lib/ratatouille/hash.rb
71
71
  - lib/ratatouille/nilclass.rb
72
72
  - lib/ratatouille/ratifier.rb
73
- - lib/ratatouille/string.rb
74
73
  - lib/ratatouille/version.rb
75
74
  - ratatouille.gemspec
76
- - spec/lib/ratatouille/array_spec.rb
77
- - spec/lib/ratatouille/hash_spec.rb
78
- - spec/lib/ratatouille/nilclass_spec.rb
79
- - spec/lib/ratatouille/ratifier_spec.rb
75
+ - spec/lib/ratatouille_ratifier_spec.rb
80
76
  - spec/lib/ratatouille_spec.rb
77
+ - spec/ratifier_spec.rb
81
78
  - spec/spec_helper.rb
82
79
  homepage: http://github.com/CITguy/ratatouille
83
80
  licenses: []
@@ -113,10 +110,8 @@ signing_key:
113
110
  specification_version: 3
114
111
  summary: DSL for validating complex hashes
115
112
  test_files:
116
- - spec/lib/ratatouille/array_spec.rb
117
- - spec/lib/ratatouille/hash_spec.rb
118
- - spec/lib/ratatouille/nilclass_spec.rb
119
- - spec/lib/ratatouille/ratifier_spec.rb
113
+ - spec/lib/ratatouille_ratifier_spec.rb
120
114
  - spec/lib/ratatouille_spec.rb
115
+ - spec/ratifier_spec.rb
121
116
  - spec/spec_helper.rb
122
117
  has_rdoc:
@@ -1,6 +0,0 @@
1
- # Monkey Patch String class
2
- class String
3
- def blank?
4
- return self.chomp.empty?
5
- end
6
- end
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Ratatouille::ArrayMethods" do
4
- [ :is_empty,
5
- :is_not_empty,
6
- :min_length,
7
- :max_length,
8
- :length_between
9
- ].each do |m|
10
- it "block context should respond to #{m}" do
11
- r = nil
12
- RatifierTest.new([]) { r = self }
13
- r.should respond_to m
14
- end
15
- end
16
-
17
- describe "is_empty" do
18
- it "should not be valid for non-empty array" do
19
- RatifierTest.new(['bar']){ is_empty }.should_not be_valid
20
- end
21
-
22
- it "should be valid for empty array" do
23
- RatifierTest.new([]){ is_empty }.should be_valid
24
- end
25
- end
26
-
27
- describe "is_not_empty" do
28
- it "should be valid for non-empty array" do
29
- RatifierTest.new(['bar']){ is_not_empty }.should be_valid
30
- end
31
-
32
- it "should not be valid for empty array" do
33
- RatifierTest.new([]){ is_not_empty }.should_not be_valid
34
- end
35
- end
36
-
37
- describe "length_between" do
38
- describe "for empty array" do
39
- before(:each) do
40
- @arr = []
41
- end
42
-
43
- it "should be valid with 0 min length and any positive, non-zero max_length" do
44
- RatifierTest.new(@arr) { length_between(0) }.should be_valid
45
- RatifierTest.new(@arr) { length_between(0, 0) }.should_not be_valid
46
- RatifierTest.new(@arr) { length_between(0, 1) }.should be_valid
47
- end
48
-
49
- it "should be invalid with 1 min_length and any max_length" do
50
- RatifierTest.new(@arr) { length_between(1) }.should_not be_valid
51
- RatifierTest.new(@arr) { length_between(1,1) }.should_not be_valid
52
- RatifierTest.new(@arr) { length_between(1,2) }.should_not be_valid
53
- end
54
- end
55
-
56
- describe "for Array with 2 elements" do
57
- before(:each) do
58
- @arr = ['foo', 'bar']
59
- end
60
-
61
- it "should be valid with 1 min_length and any max_length above 1" do
62
- RatifierTest.new(@arr) { length_between(1,1) }.should_not be_valid
63
- RatifierTest.new(@arr) { length_between(1,2) }.should be_valid
64
- end
65
-
66
- it "should be invalid with 0 min_length and any max_length less than 2" do
67
- RatifierTest.new(@arr) { length_between(0,0) }.should_not be_valid
68
- RatifierTest.new(@arr) { length_between(0,1) }.should_not be_valid
69
- RatifierTest.new(@arr) { length_between(0,2) }.should be_valid
70
- end
71
- end
72
- end
73
-
74
- describe "max_length" do
75
- it "should be valid for proper length array with integer argument" do
76
- RatifierTest.new([]) { max_length(1) }.should be_valid
77
- RatifierTest.new(['foo']) { max_length(1) }.should be_valid
78
-
79
- RatifierTest.new(['foo']) { max_length(0) }.should_not be_valid
80
- end
81
-
82
- it "should be invalid for non-numeric length" do
83
- RatifierTest.new([]) { max_length({}) }.should_not be_valid
84
- end
85
-
86
- it "should be valid for properly transformed float values" do
87
- RatifierTest.new(['foo']) { max_length(0.3) }.should_not be_valid
88
- RatifierTest.new(['foo']) { max_length(1.3) }.should be_valid
89
- RatifierTest.new(['foo', 'bar']) { max_length(1.3) }.should_not be_valid
90
- end
91
- end
92
-
93
- describe "min_length" do
94
- it "should be valid for proper length array with integer argument" do
95
- RatifierTest.new([]) { min_length(0) }.should be_valid
96
- RatifierTest.new([]) { min_length(1) }.should_not be_valid
97
-
98
- RatifierTest.new(['foo']) { min_length(0) }.should be_valid
99
- RatifierTest.new(['foo']) { min_length(1) }.should be_valid
100
- end
101
-
102
- it "should be invalid for non-numeric length" do
103
- RatifierTest.new([]) { min_length({}) }.should_not be_valid
104
- end
105
-
106
- it "should be valid for properly transformed float values" do
107
- RatifierTest.new([]) { min_length(0.3) }.should be_valid
108
- RatifierTest.new([]) { min_length(1.3) }.should_not be_valid
109
- end
110
- end
111
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Ratatouille::HashMethods" do
4
- describe "is_empty" do
5
- it "should be invalid for non-empty Hash" do
6
- RatifierTest.new({:bar => 'biz'}){ is_empty }.should_not be_valid
7
- end
8
-
9
- it "should be valid for empty Hash" do
10
- RatifierTest.new({}){ is_empty }.should be_valid
11
- end
12
- end
13
-
14
- describe "is_not_empty" do
15
- it "should be valid for non-empty hash" do
16
- RatifierTest.new({:bar => "biz"}){ is_not_empty }.should be_valid
17
- end
18
-
19
- it "should not be valid for empty hash" do
20
- RatifierTest.new({}){ is_not_empty }.should_not be_valid
21
- end
22
- end
23
-
24
- describe "choice_of" do
25
- it "should be invalid if key list is empty" do
26
- RatifierTest.new({}) { choice_of(1, []) }.should_not be_valid
27
- end
28
-
29
- it "should be invalid if choice size less than 1" do
30
- RatifierTest.new({}) { choice_of(0, [:foo]) }.should_not be_valid
31
- end
32
-
33
- it "should be invalid if choice list is not 1 more than choice size" do
34
- RatifierTest.new({}) { choice_of(1, [:foo]) }.should_not be_valid
35
- end
36
- end
37
-
38
- describe "required_keys" do
39
- it "should be valid if Has contains all required keys" do
40
- RatifierTest.new({:foo => "foo"}) { required_keys(:foo, :bar) }.should_not be_valid
41
- end
42
-
43
- it "should be invalid if hash is empty and key list is not" do
44
- RatifierTest.new({}) { required_keys(:foo) }.should_not be_valid
45
- end
46
-
47
- it "should be invalid if Hash does not contain ALL keys in key list" do
48
- RatifierTest.new({:foo => "foo"}) { required_keys(:foo, :bar) }.should_not be_valid
49
- end
50
- end
51
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe NilClass do
4
- describe "empty?" do
5
- it "should return true" do
6
- nil.should be_empty
7
- end
8
- end
9
- end