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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/opt_parse_validator/opts/regexp.rb +12 -0
- data/lib/opt_parse_validator/opts.rb +1 -1
- data/lib/opt_parse_validator/version.rb +1 -1
- data/lib/opt_parse_validator.rb +1 -1
- data/opt_parse_validator.gemspec +14 -4
- metadata +7 -62
- data/.gitignore +0 -4
- data/.rspec +0 -2
- data/.rubocop.yml +0 -6
- data/.travis.yml +0 -19
- data/Gemfile +0 -6
- data/Rakefile +0 -9
- data/spec/fixtures/options_file/default.json +0 -4
- data/spec/fixtures/options_file/malformed.json +0 -4
- data/spec/fixtures/options_file/override.yml +0 -1
- data/spec/fixtures/options_file/unsupported.ext +0 -1
- data/spec/fixtures/r.txt +0 -1
- data/spec/fixtures/rwx.txt +0 -1
- data/spec/lib/opt_parse_validator/options_file_spec.rb +0 -48
- data/spec/lib/opt_parse_validator/opts/array_spec.rb +0 -74
- data/spec/lib/opt_parse_validator/opts/base_spec.rb +0 -188
- data/spec/lib/opt_parse_validator/opts/boolean_spec.rb +0 -34
- data/spec/lib/opt_parse_validator/opts/choice_spec.rb +0 -78
- data/spec/lib/opt_parse_validator/opts/credentials_spec.rb +0 -21
- data/spec/lib/opt_parse_validator/opts/direcyory_path_spec.rb +0 -23
- data/spec/lib/opt_parse_validator/opts/file_path_spec.rb +0 -91
- data/spec/lib/opt_parse_validator/opts/integer_range_spec.rb +0 -54
- data/spec/lib/opt_parse_validator/opts/integer_spec.rb +0 -17
- data/spec/lib/opt_parse_validator/opts/multi_choices_spec.rb +0 -105
- data/spec/lib/opt_parse_validator/opts/path_spec.rb +0 -5
- data/spec/lib/opt_parse_validator/opts/positive_integer_spec.rb +0 -17
- data/spec/lib/opt_parse_validator/opts/proxy_spec.rb +0 -10
- data/spec/lib/opt_parse_validator/opts/uri_spec.rb +0 -73
- data/spec/lib/opt_parse_validator/opts/url_spec.rb +0 -26
- data/spec/lib/opt_parse_validator/version_spec.rb +0 -7
- data/spec/lib/opt_parse_validator_spec.rb +0 -185
- data/spec/spec_helper.rb +0 -25
@@ -1,185 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe OptParseValidator::OptParser do
|
4
|
-
subject(:parser) { described_class.new }
|
5
|
-
let(:verbose_opt) { OptParseValidator::OptBase.new(%w(-v --verbose)) }
|
6
|
-
let(:url_opt) { OptParseValidator::OptURL.new(['-u', '--url URL'], required: true) }
|
7
|
-
|
8
|
-
describe '#add_option' do
|
9
|
-
after do
|
10
|
-
if @exception
|
11
|
-
expect { parser.add_option(@option) }.to raise_error(@exception)
|
12
|
-
else
|
13
|
-
parser.add_option(@option)
|
14
|
-
|
15
|
-
expect(parser.symbols_used).to eq @expected_symbols
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'when not an OptBase' do
|
20
|
-
it 'raises an error' do
|
21
|
-
@option = 'just a string'
|
22
|
-
@exception = 'The option is not an OptBase, String supplied'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when the option symbol is already used' do
|
27
|
-
it 'raises an error' do
|
28
|
-
@option = verbose_opt
|
29
|
-
@exception = 'The option verbose is already used !'
|
30
|
-
parser.add_option(@option)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when a valid option' do
|
35
|
-
let(:option) { OptParseValidator::OptBase.new(['-u', '--url URL']) }
|
36
|
-
|
37
|
-
it 'sets the option' do
|
38
|
-
@option = option
|
39
|
-
@expected_symbols = [:url]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#add' do
|
45
|
-
context 'when not an Array<OptBase> or an OptBase' do
|
46
|
-
after { expect { parser.add(*@options) }.to raise_error(@exception) }
|
47
|
-
|
48
|
-
it 'raises an error when an Array<String>' do
|
49
|
-
@options = ['string', 'another one']
|
50
|
-
@exception = 'The option is not an OptBase, String supplied'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when valid' do
|
55
|
-
after do
|
56
|
-
parser.add(*@options)
|
57
|
-
|
58
|
-
expect(parser.symbols_used).to eq @expected_symbols
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'adds the options' do
|
62
|
-
@options = [verbose_opt, url_opt]
|
63
|
-
@expected_symbols = [:verbose, :url]
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'adds the option' do
|
67
|
-
@options = verbose_opt
|
68
|
-
@expected_symbols = [:verbose]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#results' do
|
74
|
-
before { parser.add(*options) }
|
75
|
-
|
76
|
-
after do
|
77
|
-
if @expected
|
78
|
-
expect(parser.results(@argv)).to eq @expected
|
79
|
-
else
|
80
|
-
expect { parser.results(@argv) }.to raise_error(@exception)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
let(:options) { [verbose_opt, url_opt] }
|
85
|
-
|
86
|
-
context 'when an option is required but not supplied' do
|
87
|
-
it 'raises an error' do
|
88
|
-
@exception = 'The option url is required'
|
89
|
-
@argv = %w(-v)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'when the #validate raises an error' do
|
94
|
-
it 'adds the option.to_long as a prefix' do
|
95
|
-
@exception = Addressable::URI::InvalidURIError
|
96
|
-
@argv = %w(--url www.google.com)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'when :requied_unless' do
|
101
|
-
let(:url_opt) { OptParseValidator::OptURL.new(['--url URL'], required_unless: :update) }
|
102
|
-
let(:update_opt) { OptParseValidator::OptBoolean.new(['--update'], required_unless: [:url]) }
|
103
|
-
let(:options) { [url_opt, update_opt, verbose_opt] }
|
104
|
-
|
105
|
-
context 'when none supplied' do
|
106
|
-
it 'raises an error' do
|
107
|
-
@exception = 'One of the following options is required: url, update'
|
108
|
-
@argv = %w(-v)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'when --url' do
|
113
|
-
it 'returns the expected value' do
|
114
|
-
@expected = { url: 'http://www.g.com' }
|
115
|
-
@argv = %w(--url http://www.g.com)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'when --update' do
|
120
|
-
it 'returns the expected value' do
|
121
|
-
@expected = { update: true }
|
122
|
-
@argv = %w(--update)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'when --url and --update' do
|
127
|
-
it 'returns the expected values' do
|
128
|
-
@expected = { url: 'http://www.g.com', update: true, verbose: true }
|
129
|
-
@argv = %w(--url http://www.g.com --update -v)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'when the default attribute is used' do
|
135
|
-
let(:options) { [verbose_opt, default_opt] }
|
136
|
-
let(:default_opt) { OptParseValidator::OptBase.new(['--default VALUE'], default: false) }
|
137
|
-
|
138
|
-
context 'when the option is supplied' do
|
139
|
-
it 'overrides the default value' do
|
140
|
-
@argv = %w(--default overriden)
|
141
|
-
@expected = { default: 'overriden' }
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'when the option is not supplied' do
|
146
|
-
it 'sets the default value' do
|
147
|
-
@argv = %w(-v)
|
148
|
-
@expected = { verbose: true, default: false }
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# See https://github.com/wpscanteam/CMSScanner/issues/2
|
154
|
-
context 'when no short option' do
|
155
|
-
let(:options) { [verbose_opt, http_opt] }
|
156
|
-
let(:http_opt) { OptParseValidator::OptBase.new(['--http-auth log:pass']) }
|
157
|
-
|
158
|
-
it 'calls the help' do
|
159
|
-
expect(parser).to receive(:help)
|
160
|
-
|
161
|
-
@argv = %w(-h)
|
162
|
-
@exception = SystemExit
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'returns the results' do
|
166
|
-
@argv = %w(--http-auth user:passwd)
|
167
|
-
@expected = { http_auth: 'user:passwd' }
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'when the normalize attrbite is used' do
|
172
|
-
let(:options) { [OptParseValidator::OptString.new(['--test V'], normalize: :to_sym)] }
|
173
|
-
|
174
|
-
it 'returns the symbol' do
|
175
|
-
@argv = %w(--test test)
|
176
|
-
@expected = { test: :test }
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'returns the results' do
|
181
|
-
@argv = %w(--url http://hello.com -v)
|
182
|
-
@expected = { url: 'http://hello.com', verbose: true }
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
|
4
|
-
FIXTURES = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
5
|
-
|
6
|
-
require 'rspec/its'
|
7
|
-
require 'simplecov'
|
8
|
-
|
9
|
-
if ENV['TRAVIS']
|
10
|
-
require 'coveralls'
|
11
|
-
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
12
|
-
end
|
13
|
-
|
14
|
-
SimpleCov.start do
|
15
|
-
add_filter '/spec/'
|
16
|
-
end
|
17
|
-
|
18
|
-
# See http://betterspecs.org/
|
19
|
-
RSpec.configure do |config|
|
20
|
-
config.expect_with :rspec do |c|
|
21
|
-
c.syntax = :expect
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'opt_parse_validator'
|