compel 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,73 @@
1
+ describe Compel::Validation do
2
+
3
+ context 'Param validation' do
4
+
5
+ context 'required' do
6
+
7
+ it 'should validate without errors' do
8
+ errors = Compel::Validation.validate(123, { required: true })
9
+
10
+ expect(errors.empty?).to eq(true)
11
+ end
12
+
13
+ it 'should validate with error' do
14
+ errors = Compel::Validation.validate(nil, { required: true })
15
+
16
+ expect(errors.empty?).to eq(false)
17
+ expect(errors).to eq(['is required'])
18
+ end
19
+
20
+ end
21
+
22
+ context 'length' do
23
+
24
+ it 'should validate without errors' do
25
+ errors = Compel::Validation.validate(123, { length: 3 })
26
+
27
+ expect(errors.empty?).to eq(true)
28
+ end
29
+
30
+ end
31
+
32
+ context 'in, within, range' do
33
+
34
+ def expect_be_in_within_range(range, value)
35
+ [:in, :within].each do |key|
36
+ errors = Compel::Validation.validate(value, { key => range })
37
+ yield errors
38
+ end
39
+ end
40
+
41
+ it 'should validate without errors' do
42
+ expect_be_in_within_range(['PT', 'UK'], 'PT') do |errors|
43
+ expect(errors.empty?).to eq(true)
44
+ end
45
+ end
46
+
47
+ it 'should validate with errors' do
48
+ expect_be_in_within_range(['PT', 'UK'], 'US') do |errors|
49
+ expect(errors).to eq(['must be within ["PT", "UK"]'])
50
+ end
51
+ end
52
+
53
+ context 'range' do
54
+
55
+ it 'should validate without errors' do
56
+ errors = Compel::Validation.validate(2, range: (1..3))
57
+
58
+ expect(errors.empty?).to eq(true)
59
+ end
60
+
61
+ it 'should validate with errors' do
62
+ errors = Compel::Validation.validate(4, range: (1..3))
63
+
64
+ expect(errors).to eq(['must be within 1..3'])
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1 @@
1
+ require 'compel'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Joaquim Adráz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Compel
70
+ email:
71
+ - joaquim.adraz@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - compel.gemspec
84
+ - lib/compel.rb
85
+ - lib/compel/coercion.rb
86
+ - lib/compel/coercion/boolean.rb
87
+ - lib/compel/coercion/date.rb
88
+ - lib/compel/coercion/datetime.rb
89
+ - lib/compel/coercion/float.rb
90
+ - lib/compel/coercion/hash.rb
91
+ - lib/compel/coercion/integer.rb
92
+ - lib/compel/coercion/json.rb
93
+ - lib/compel/coercion/string.rb
94
+ - lib/compel/coercion/time.rb
95
+ - lib/compel/coercion/type.rb
96
+ - lib/compel/contract.rb
97
+ - lib/compel/errors.rb
98
+ - lib/compel/invalid_params_error.rb
99
+ - lib/compel/param.rb
100
+ - lib/compel/param_type_error.rb
101
+ - lib/compel/param_validation_error.rb
102
+ - lib/compel/validation.rb
103
+ - lib/compel/version.rb
104
+ - spec/compel/coercion_spec.rb
105
+ - spec/compel/compel_spec.rb
106
+ - spec/compel/contract_spec.rb
107
+ - spec/compel/errors_spec.rb
108
+ - spec/compel/param_spec.rb
109
+ - spec/compel/validation_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/joaquimadraz/compel
112
+ licenses: []
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.5.1
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Ruby Hash Coercion and Validation
134
+ test_files:
135
+ - spec/compel/coercion_spec.rb
136
+ - spec/compel/compel_spec.rb
137
+ - spec/compel/contract_spec.rb
138
+ - spec/compel/errors_spec.rb
139
+ - spec/compel/param_spec.rb
140
+ - spec/compel/validation_spec.rb
141
+ - spec/spec_helper.rb