opt_parse_validator 0.0.9 → 0.0.10

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/opt_parse_validator/opts/regexp.rb +12 -0
  4. data/lib/opt_parse_validator/opts.rb +1 -1
  5. data/lib/opt_parse_validator/version.rb +1 -1
  6. data/lib/opt_parse_validator.rb +1 -1
  7. data/opt_parse_validator.gemspec +14 -4
  8. metadata +7 -62
  9. data/.gitignore +0 -4
  10. data/.rspec +0 -2
  11. data/.rubocop.yml +0 -6
  12. data/.travis.yml +0 -19
  13. data/Gemfile +0 -6
  14. data/Rakefile +0 -9
  15. data/spec/fixtures/options_file/default.json +0 -4
  16. data/spec/fixtures/options_file/malformed.json +0 -4
  17. data/spec/fixtures/options_file/override.yml +0 -1
  18. data/spec/fixtures/options_file/unsupported.ext +0 -1
  19. data/spec/fixtures/r.txt +0 -1
  20. data/spec/fixtures/rwx.txt +0 -1
  21. data/spec/lib/opt_parse_validator/options_file_spec.rb +0 -48
  22. data/spec/lib/opt_parse_validator/opts/array_spec.rb +0 -74
  23. data/spec/lib/opt_parse_validator/opts/base_spec.rb +0 -188
  24. data/spec/lib/opt_parse_validator/opts/boolean_spec.rb +0 -34
  25. data/spec/lib/opt_parse_validator/opts/choice_spec.rb +0 -78
  26. data/spec/lib/opt_parse_validator/opts/credentials_spec.rb +0 -21
  27. data/spec/lib/opt_parse_validator/opts/direcyory_path_spec.rb +0 -23
  28. data/spec/lib/opt_parse_validator/opts/file_path_spec.rb +0 -91
  29. data/spec/lib/opt_parse_validator/opts/integer_range_spec.rb +0 -54
  30. data/spec/lib/opt_parse_validator/opts/integer_spec.rb +0 -17
  31. data/spec/lib/opt_parse_validator/opts/multi_choices_spec.rb +0 -105
  32. data/spec/lib/opt_parse_validator/opts/path_spec.rb +0 -5
  33. data/spec/lib/opt_parse_validator/opts/positive_integer_spec.rb +0 -17
  34. data/spec/lib/opt_parse_validator/opts/proxy_spec.rb +0 -10
  35. data/spec/lib/opt_parse_validator/opts/uri_spec.rb +0 -73
  36. data/spec/lib/opt_parse_validator/opts/url_spec.rb +0 -26
  37. data/spec/lib/opt_parse_validator/version_spec.rb +0 -7
  38. data/spec/lib/opt_parse_validator_spec.rb +0 -185
  39. data/spec/spec_helper.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e79a03f62b4755570f5b2639381b31b9900c92f4
4
- data.tar.gz: 2f35d0102777f6ba8d069d01a52850ee7e8d2209
3
+ metadata.gz: b9f84ae1d23fed8ad36be7b431234657f5c9cbc3
4
+ data.tar.gz: b813aa3f972db1171b96ac7442d7aa14597296b5
5
5
  SHA512:
6
- metadata.gz: e8e2380fe532f69f49df35aa7f38112118a47f97fc70304eb32b2c0a668f002317c6444afde1dd9f0f0a15def4a3e888468093a4fea86515e7082e051ae2ac0a
7
- data.tar.gz: bfbd27858ac145c2e80979639e5356fefb53ae4f989ee23a30f4316315effa653f096bb99bc4997b97d899df17f0df7b2bd542dcc40389ff10ec2ecf2f6279c9
6
+ metadata.gz: e92ff979aa85b9020e5044512451d4d291a548f49e69d6aa51d1487444609cd25fabe346ef111912532aa88b8a775f90bc2e276dc6f2f74c31ca12f23e06b6d6
7
+ data.tar.gz: 07f1cb36452e4f4ed87c3263744afa32185f0bd8f05c03312eccca0deb6698c2ba1cdb30033d2f16a4331e688e21a58f5c0217e6bf228b4a56df569cc9e580cb
data/README.md CHANGED
@@ -43,6 +43,8 @@ OptParseValidator
43
43
  - Proxy
44
44
  - :protocols
45
45
  - :default_protocol
46
+ - Regexp:
47
+ - :options (See http://ruby-doc.org/core-2.2.1/Regexp.html#method-c-new)
46
48
  - String
47
49
  - URI
48
50
  - :protocols
@@ -0,0 +1,12 @@
1
+ module OptParseValidator
2
+ # Implementation of the Regexp Option
3
+ # See http://ruby-doc.org/core-2.2.1/Regexp.html#method-c-new for expected values in :options
4
+ class OptRegexp < OptBase
5
+ # @param [ String ] value
6
+ #
7
+ # @return [ Regexp ]
8
+ def validate(value)
9
+ Regexp.new(super(value), attrs[:options])
10
+ end
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
1
  %w(
2
2
  base string integer positive_integer choice boolean uri url proxy credentials
3
- path file_path directory_path array integer_range multi_choices
3
+ path file_path directory_path array integer_range multi_choices regexp
4
4
  ).each do |opt|
5
5
  require 'opt_parse_validator/opts/' + opt
6
6
  end
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module OptParseValidator
3
- VERSION = '0.0.9'
3
+ VERSION = '0.0.10'
4
4
  end
@@ -37,7 +37,7 @@ module OptParseValidator
37
37
  fail "The option is not an OptBase, #{opt.class} supplied" unless opt.is_a?(OptBase)
38
38
  fail "The option #{opt.to_sym} is already used !" if @symbols_used.include?(opt.to_sym)
39
39
 
40
- @opts << opt
40
+ @opts << opt
41
41
  @symbols_used << opt.to_sym
42
42
  # Set the default option value if it exists
43
43
  @results[opt.to_sym] = opt.default unless opt.default.nil?
@@ -16,9 +16,19 @@ Gem::Specification.new do |s|
16
16
  s.homepage = 'https://github.com/wpscanteam/OptParseValidator'
17
17
  s.license = 'MIT'
18
18
 
19
- s.files = `git ls-files -z`.split("\x0")
20
- s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
21
- s.test_files = s.files.grep(/^(test|spec|features)\//)
19
+ s.files = `git ls-files -z`.split("\x0").reject do |file|
20
+ file =~ %r{^(?:
21
+ spec\/.*
22
+ |Gemfile
23
+ |Rakefile
24
+ |\.rspec
25
+ |\.gitignore
26
+ |\.rubocop.yml
27
+ |\.travis.yml
28
+ )$}x
29
+ end
30
+ s.test_files = []
31
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
32
  s.require_paths = ['lib']
23
33
 
24
34
  s.add_dependency 'addressable', '~> 2.3'
@@ -27,6 +37,6 @@ Gem::Specification.new do |s|
27
37
  s.add_development_dependency 'rspec', '~> 3.2'
28
38
  s.add_development_dependency 'rspec-its', '~> 1.1'
29
39
  s.add_development_dependency 'bundler', '~> 1.6'
30
- s.add_development_dependency 'rubocop', '~> 0.29'
40
+ s.add_development_dependency 'rubocop', '~> 0.30'
31
41
  s.add_development_dependency 'simplecov', '~> 0.9'
32
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opt_parse_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - WPScanTeam - Erwan le Rousseau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.29'
89
+ version: '0.30'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.29'
96
+ version: '0.30'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -115,15 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".gitignore"
119
- - ".rspec"
120
- - ".rubocop.yml"
121
118
  - ".simplecov"
122
- - ".travis.yml"
123
- - Gemfile
124
119
  - LICENSE
125
120
  - README.md
126
- - Rakefile
127
121
  - lib/opt_parse_validator.rb
128
122
  - lib/opt_parse_validator/hacks.rb
129
123
  - lib/opt_parse_validator/options_file.rb
@@ -141,36 +135,12 @@ files:
141
135
  - lib/opt_parse_validator/opts/path.rb
142
136
  - lib/opt_parse_validator/opts/positive_integer.rb
143
137
  - lib/opt_parse_validator/opts/proxy.rb
138
+ - lib/opt_parse_validator/opts/regexp.rb
144
139
  - lib/opt_parse_validator/opts/string.rb
145
140
  - lib/opt_parse_validator/opts/uri.rb
146
141
  - lib/opt_parse_validator/opts/url.rb
147
142
  - lib/opt_parse_validator/version.rb
148
143
  - opt_parse_validator.gemspec
149
- - spec/fixtures/options_file/default.json
150
- - spec/fixtures/options_file/malformed.json
151
- - spec/fixtures/options_file/override.yml
152
- - spec/fixtures/options_file/unsupported.ext
153
- - spec/fixtures/r.txt
154
- - spec/fixtures/rwx.txt
155
- - spec/lib/opt_parse_validator/options_file_spec.rb
156
- - spec/lib/opt_parse_validator/opts/array_spec.rb
157
- - spec/lib/opt_parse_validator/opts/base_spec.rb
158
- - spec/lib/opt_parse_validator/opts/boolean_spec.rb
159
- - spec/lib/opt_parse_validator/opts/choice_spec.rb
160
- - spec/lib/opt_parse_validator/opts/credentials_spec.rb
161
- - spec/lib/opt_parse_validator/opts/direcyory_path_spec.rb
162
- - spec/lib/opt_parse_validator/opts/file_path_spec.rb
163
- - spec/lib/opt_parse_validator/opts/integer_range_spec.rb
164
- - spec/lib/opt_parse_validator/opts/integer_spec.rb
165
- - spec/lib/opt_parse_validator/opts/multi_choices_spec.rb
166
- - spec/lib/opt_parse_validator/opts/path_spec.rb
167
- - spec/lib/opt_parse_validator/opts/positive_integer_spec.rb
168
- - spec/lib/opt_parse_validator/opts/proxy_spec.rb
169
- - spec/lib/opt_parse_validator/opts/uri_spec.rb
170
- - spec/lib/opt_parse_validator/opts/url_spec.rb
171
- - spec/lib/opt_parse_validator/version_spec.rb
172
- - spec/lib/opt_parse_validator_spec.rb
173
- - spec/spec_helper.rb
174
144
  homepage: https://github.com/wpscanteam/OptParseValidator
175
145
  licenses:
176
146
  - MIT
@@ -191,33 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
161
  version: '0'
192
162
  requirements: []
193
163
  rubyforge_project:
194
- rubygems_version: 2.4.5
164
+ rubygems_version: 2.4.6
195
165
  signing_key:
196
166
  specification_version: 4
197
167
  summary: Testing Gem
198
- test_files:
199
- - spec/fixtures/options_file/default.json
200
- - spec/fixtures/options_file/malformed.json
201
- - spec/fixtures/options_file/override.yml
202
- - spec/fixtures/options_file/unsupported.ext
203
- - spec/fixtures/r.txt
204
- - spec/fixtures/rwx.txt
205
- - spec/lib/opt_parse_validator/options_file_spec.rb
206
- - spec/lib/opt_parse_validator/opts/array_spec.rb
207
- - spec/lib/opt_parse_validator/opts/base_spec.rb
208
- - spec/lib/opt_parse_validator/opts/boolean_spec.rb
209
- - spec/lib/opt_parse_validator/opts/choice_spec.rb
210
- - spec/lib/opt_parse_validator/opts/credentials_spec.rb
211
- - spec/lib/opt_parse_validator/opts/direcyory_path_spec.rb
212
- - spec/lib/opt_parse_validator/opts/file_path_spec.rb
213
- - spec/lib/opt_parse_validator/opts/integer_range_spec.rb
214
- - spec/lib/opt_parse_validator/opts/integer_spec.rb
215
- - spec/lib/opt_parse_validator/opts/multi_choices_spec.rb
216
- - spec/lib/opt_parse_validator/opts/path_spec.rb
217
- - spec/lib/opt_parse_validator/opts/positive_integer_spec.rb
218
- - spec/lib/opt_parse_validator/opts/proxy_spec.rb
219
- - spec/lib/opt_parse_validator/opts/uri_spec.rb
220
- - spec/lib/opt_parse_validator/opts/url_spec.rb
221
- - spec/lib/opt_parse_validator/version_spec.rb
222
- - spec/lib/opt_parse_validator_spec.rb
223
- - spec/spec_helper.rb
168
+ test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- coverage
2
- pkg
3
- Gemfile.lock
4
- *.gem
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --fail-fast
data/.rubocop.yml DELETED
@@ -1,6 +0,0 @@
1
- LineLength:
2
- Enabled: false
3
- MethodLength:
4
- Max: 20
5
- Metrics/AbcSize:
6
- Enabled: false
data/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.1.1
6
- - 2.1.2
7
- - 2.1.3
8
- - 2.1.4
9
- - 2.1.5
10
- - 2.2.0
11
- - ruby-head
12
- matrix:
13
- allow_failures:
14
- - rvm: ruby-head
15
- before_script:
16
- - chmod 0400 spec/fixtures/r.txt
17
- script:
18
- - bundle exec rspec
19
- - bundle exec rubocop
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- group :test do
5
- gem 'coveralls', '~> 0.7', require: false
6
- end
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'rubocop/rake_task'
4
-
5
- RuboCop::RakeTask.new
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- # Run rubocop & rspec before the build
9
- task build: [:rubocop, :spec]
@@ -1,4 +0,0 @@
1
- {
2
- "verbose": true,
3
- "override_me": "I should be overriden"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "verbose": true,
3
- "":,
4
- }
@@ -1 +0,0 @@
1
- override_me: "Yeaa"
@@ -1 +0,0 @@
1
- Unsupported file format
data/spec/fixtures/r.txt DELETED
@@ -1 +0,0 @@
1
- This file is a chmod 400
@@ -1 +0,0 @@
1
- This file is a chmod 777
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OptParseValidator::OptParser do
4
- subject(:parser) { described_class.new }
5
- let(:fixtures) { File.join(FIXTURES, 'options_file') }
6
- let(:default_file) { File.join(fixtures, 'default.json') }
7
- let(:override_file) { File.join(fixtures, 'override.yml') }
8
-
9
- describe '#load_options_files' do
10
- context 'when error' do
11
- before { parser.options_files << config_file }
12
-
13
- context 'when the format is not supported' do
14
- let(:config_file) { File.join(fixtures, 'unsupported.ext') }
15
- let(:exception) { "The format #{File.extname(config_file).delete('.')} is not supported" }
16
-
17
- it 'raises an error' do
18
- expect { parser.load_options_files }.to raise_error(exception)
19
- end
20
- end
21
-
22
- context 'when file content is malformed' do
23
- let(:config_file) { File.join(fixtures, 'malformed.json') }
24
- let(:exception) { "Parse Error, #{config_file} seems to be malformed" }
25
-
26
- it 'raises an error' do
27
- expect { parser.load_options_files }.to raise_error(exception)
28
- end
29
- end
30
- end
31
-
32
- context 'otherwise' do
33
- let(:verbose_opt) { OptParseValidator::OptBoolean.new(%w(-v --verbose)) }
34
- let(:override_opt) { OptParseValidator::OptString.new(['--override-me VALUE'], normalize: :to_sym) }
35
-
36
- let(:opts) { [verbose_opt, override_opt] }
37
-
38
- let(:expected) { { verbose: true, override_me: :Yeaa } }
39
-
40
- it 'sets everything correctly and get the right results' do
41
- parser.options_files << default_file << override_file
42
- parser.add(*opts)
43
-
44
- expect(parser.results([])).to eq expected
45
- end
46
- end
47
- end
48
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OptParseValidator::OptArray do
4
- subject(:opt) { described_class.new(['-a', '--array VALUES'], attrs) }
5
- let(:attrs) { {} }
6
-
7
- describe '#validate' do
8
- context 'when an empty or nil value is given' do
9
- context 'when no value_if_empty attribute' do
10
- it 'raises an error' do
11
- [nil, ''].each do |value|
12
- expect { opt.validate(value) }.to raise_error('Empty option value supplied')
13
- end
14
- end
15
- end
16
-
17
- context 'when value_if_empty attribute' do
18
- let(:attrs) { super().merge(value_if_empty: 'a,b') }
19
-
20
- it 'returns the expected array' do
21
- [nil, ''].each do |value|
22
- expect(opt.validate(value)).to eql %w(a b)
23
- end
24
- end
25
- end
26
- end
27
-
28
- context 'when the separator is not supplied' do
29
- context 'when not present in the argument' do
30
- it 'returns an array with the correct value' do
31
- expect(opt.validate('rspec')).to eql %w(rspec)
32
- end
33
- end
34
-
35
- context 'when present' do
36
- it 'returns the expected array' do
37
- expect(opt.validate('r1,r2,r3')).to eql %w(r1 r2 r3)
38
- end
39
- end
40
- end
41
-
42
- context 'when separator supplied' do
43
- subject(:opt) { described_class.new(['-a', '--array VALUES'], separator: '-') }
44
-
45
- it 'returns an array with the correct value' do
46
- expect(opt.validate('r1,r2,r3')).to eql %w(r1,r2,r3)
47
- end
48
-
49
- it 'returns the expected array' do
50
- expect(opt.validate('r1-r2-r3')).to eql %w(r1 r2 r3)
51
- end
52
- end
53
- end
54
-
55
- describe '#normalize' do
56
- after { expect(opt.normalize(@value)).to eql @expected }
57
-
58
- context 'when no :normalize attribute' do
59
- it 'returns the value' do
60
- @value = %w(t1 t2)
61
- @expected = @value
62
- end
63
- end
64
-
65
- context 'when a single normalization' do
66
- let(:attrs) { { normalize: :to_sym } }
67
-
68
- it 'returns the expected value' do
69
- @value = [1.0, 'test']
70
- @expected = [1.0, :test]
71
- end
72
- end
73
- end
74
- end
@@ -1,188 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OptParseValidator::OptBase do
4
- subject(:opt) { described_class.new(option, attrs) }
5
- let(:option) { %w(-v --verbose) }
6
- let(:attrs) { {} }
7
-
8
- describe '#to_long' do
9
- after { expect(described_class.new(@option).to_long).to eql @expected }
10
-
11
- context 'when not found' do
12
- it 'returns nil' do
13
- @option = %w(-v)
14
- @expected = nil
15
- end
16
- end
17
-
18
- context 'when found' do
19
- it 'returns the long name' do
20
- @option = ['-v', '--[no-]verbose VALUE [OPT]', 'Verbose Mode']
21
- @expected = '--verbose'
22
- end
23
- end
24
- end
25
-
26
- describe '#to_sym' do
27
- after :each do
28
- if @exception
29
- expect { described_class.new(@option).to_sym }.to raise_error(@exception)
30
- else
31
- expect(described_class.new(@option).to_sym).to eql(@expected)
32
- end
33
- end
34
-
35
- context 'without REQUIRED or OPTIONAL arguments' do
36
- context 'with short option' do
37
- it 'returns :test' do
38
- @option = %w(-t --test Testing)
39
- @expected = :test
40
- end
41
-
42
- it 'returns :its_a_long_option' do
43
- @option = ['-l', '--its-a-long-option', "Testing '-' replacement"]
44
- @expected = :its_a_long_option
45
- end
46
- end
47
-
48
- context 'without short option' do
49
- it 'returns :long' do
50
- @option = ['--long']
51
- @expected = :long
52
- end
53
-
54
- it 'returns :long_option' do
55
- @option = ['--long-option', 'No short !']
56
- @expected = :long_option
57
- end
58
- end
59
-
60
- context 'without long option' do
61
- it 'raises an error' do
62
- @option = ['-v', 'long option missing']
63
- @exception = 'Could not find option symbol for ["-v", "long option missing"]'
64
- end
65
-
66
- it 'raises an error' do
67
- @option = ['long option missing']
68
- @exception = 'Could not find option symbol for ["long option missing"]'
69
- end
70
- end
71
-
72
- context 'with multiple long option names (like alias)' do
73
- it 'returns the first long option found' do
74
- @option = %w(--check-long --cl)
75
- @expected = :check_long
76
- end
77
- end
78
- end
79
-
80
- context 'when negative prefix name' do
81
- it 'returns the positive option symbol' do
82
- @option = %w(-v --[no-]verbose)
83
- @expected = :verbose
84
- end
85
- end
86
-
87
- context 'with REQUIRED or OPTIONAL arguments' do
88
- it 'should removed the OPTIONAL argument' do
89
- @option = ['-p', '--page [PAGE_NUMBER]']
90
- @expected = :page
91
- end
92
-
93
- it 'should removed the REQUIRED argument' do
94
- @option = ['--url TARGET_URL']
95
- @expected = :url
96
- end
97
- end
98
- end
99
-
100
- describe '#new, #required?' do
101
- context 'when no :required' do
102
- its(:option) { should eq(option) }
103
- its(:required?) { should be_falsey }
104
- its(:to_sym) { should eq(:verbose) }
105
- end
106
-
107
- context 'when :required' do
108
- let(:attrs) { { required: true } }
109
-
110
- its(:required?) { should be true }
111
- end
112
- end
113
-
114
- describe '#normalize' do
115
- after { expect(opt.normalize(@value)).to eql @expected }
116
-
117
- context 'when no :normalize attribute' do
118
- it 'returns the value' do
119
- @value = 'test'
120
- @expected = @value
121
- end
122
- end
123
-
124
- context 'when a single normalization' do
125
- let(:attrs) { { normalize: :to_sym } }
126
-
127
- context 'when the value does not have a to_sym method' do
128
- it 'returns the value' do
129
- @value = 1.0
130
- @expected = @value
131
- end
132
- end
133
-
134
- context 'when a to_sym method' do
135
- it 'returns the symbol' do
136
- @value = 'test'
137
- @expected = :test
138
- end
139
- end
140
- end
141
-
142
- context 'when multiple normalization' do
143
- let(:attrs) { { normalize: [:to_sym, 2.0, :upcase] } }
144
-
145
- it 'apply each of them (if possible)' do
146
- @value = 'test'
147
- @expected = :TEST
148
- end
149
- end
150
- end
151
-
152
- describe '#validate' do
153
- context 'when no value_if_empty attribute' do
154
- context 'when an empty or nil value' do
155
- it 'raises an error' do
156
- [nil, ''].each do |value|
157
- expect { opt.validate(value) }
158
- .to raise_error('Empty option value supplied')
159
- end
160
- end
161
- end
162
-
163
- context 'when a valid value' do
164
- it 'returns it' do
165
- expect(opt.validate('testing')).to eql 'testing'
166
- end
167
- end
168
- end
169
-
170
- context 'when value_if_empty attribute' do
171
- let(:attrs) { super().merge(value_if_empty: 'it works') }
172
-
173
- context 'when nil or empty value' do
174
- it 'returns the value from the value_if_empty attribute' do
175
- [nil, ''].each do |value|
176
- expect(opt.validate(value)).to eql attrs[:value_if_empty]
177
- end
178
- end
179
- end
180
-
181
- context 'when a valid value' do
182
- it 'returns it' do
183
- expect(opt.validate('tt')).to eql 'tt'
184
- end
185
- end
186
- end
187
- end
188
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OptParseValidator::OptBoolean do
4
- subject(:opt) { described_class.new(['-b', '--bool BOOL']) }
5
-
6
- describe '#validate' do
7
- context 'when does not match TRUE_PATTERN and FALSE_PATTERN' do
8
- it 'raises an error' do
9
- expect { opt.validate("true\nfalse") }
10
- .to raise_error('Invalid boolean value, expected true|t|yes|y|1|false|f|no|n|0')
11
- end
12
- end
13
-
14
- context 'when matches TRUE_PATTERN' do
15
- after { expect(opt.validate(@argument)).to be true }
16
-
17
- %w(true t yes y 1).each do |arg|
18
- it 'returns true' do
19
- @argument = arg
20
- end
21
- end
22
- end
23
-
24
- context 'when matches FALSE_PATTERN' do
25
- after { expect(opt.validate(@argument)).to be false }
26
-
27
- %w(false f no n 0).each do |arg|
28
- it 'returns false' do
29
- @argument = arg
30
- end
31
- end
32
- end
33
- end
34
- end