Commit c0b7643 1 parent 54f253b commit c0b7643 Copy full SHA for c0b7643
File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,14 @@ def to_hash
109
109
end
110
110
end
111
111
112
+ # Return whether an argument has been provided or not?
113
+ #
114
+ # @param name [Symbol]
115
+ # @return [Boolean]
116
+ def has? ( key )
117
+ @source . key? ( key . to_sym )
118
+ end
119
+
112
120
# Validate an argument set and return any errors as appropriate
113
121
#
114
122
# @param argument [Rapid::Argument]
Original file line number Diff line number Diff line change 342
342
end
343
343
end
344
344
345
+ context '#has?' do
346
+ it 'returns false when the argument has not been provided' do
347
+ as = Rapid ::ArgumentSet . create ( 'ExampleSet' ) do
348
+ argument :name , type : :string
349
+ end
350
+ instance = as . new ( { } )
351
+ expect ( instance . has? ( :name ) ) . to be false
352
+ end
353
+
354
+ it 'returns false for values that are provided but are not valid' do
355
+ as = Rapid ::ArgumentSet . create ( 'ExampleSet' ) do
356
+ argument :name , type : :string
357
+ end
358
+ instance = as . new ( { age : 10 } )
359
+ expect ( instance . has? ( :age ) ) . to be false
360
+ end
361
+
362
+ it 'returns true when the argument has been provided but is nil' do
363
+ as = Rapid ::ArgumentSet . create ( 'ExampleSet' ) do
364
+ argument :name , type : :string
365
+ end
366
+ instance = as . new ( { name : nil } )
367
+ expect ( instance . has? ( :name ) ) . to be true
368
+ end
369
+
370
+ it 'returns true when the argument has been provided' do
371
+ as = Rapid ::ArgumentSet . create ( 'ExampleSet' ) do
372
+ argument :name , type : :string
373
+ end
374
+ instance = as . new ( { name : 'Dave' } )
375
+ expect ( instance . has? ( :name ) ) . to be true
376
+ expect ( instance . has? ( 'name' ) ) . to be true
377
+ end
378
+ end
379
+
345
380
context '#to_hash' do
346
381
it 'should return a hash of the values' do
347
382
as = Rapid ::ArgumentSet . create ( 'ExampleSet' ) do
You can’t perform that action at this time.
0 commit comments