spaceborne 0.1.38 → 0.1.42

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d742ea06ad022126a7a61fb008131b02d0f0f1db485d832570b85f845299c655
4
- data.tar.gz: d7d452c83c164adebc69df71aef6aa2f12d50375be2e354463f7b7789b07c290
3
+ metadata.gz: 66c180d30b3917866f8729f651f22862158acb805ac7411494afd9bfcd2b8387
4
+ data.tar.gz: 435b8c3d85815b31eb853c71f882ae2d5ccba9597f187d21bd39b9821741d62e
5
5
  SHA512:
6
- metadata.gz: 7e16b9d1bc60eabc5257afb91510d4a715bd8ce76acccc820a255a96ad4b19f87732360d98e3dfbfcfd0f53bd2d7524a72868602df29b2bc5fa871a15128e40e
7
- data.tar.gz: 0bac75438755e532b9d39c10864d91430d9a7d281f7d89b9ee1d1943ab7951381432fb0e48ccd39bbc95725dafb8db93a99ba4edc9a53eebec3d6c4bc8e15e59
6
+ metadata.gz: 01f34ca4e5cf037f0d5a33e5739f67e542409d9ce9acb6350009e937f435cc199ad136f95ae67e2f156801d453e4f1c99a93098d9b04e7341231f90bd4092ec6
7
+ data.tar.gz: bb5bf155fa4f106c410c680948b796506b53e3972f6d932ae8efd51660362a7de95de858a122689da2d7b05da6f09e43839779a4701d96335445461b044602c6
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+
1
4
  Style/FrozenStringLiteralComment:
2
5
  Enabled: false
3
6
 
@@ -23,7 +26,7 @@ Metrics/ClassLength:
23
26
  Exclude:
24
27
  - 'bin/*'
25
28
 
26
- Metrics/LineLength:
29
+ Layout/LineLength:
27
30
  Exclude:
28
31
  - 'spec/airborne/**/*.rb'
29
32
 
data/README.md CHANGED
@@ -226,15 +226,16 @@ The following example shows how extensions # 6 & 8 work
226
226
  { "array": [] },
227
227
  { "foo": "bar" }],
228
228
  "highest_array": [ null,
229
- { "array": [{ "present": "name" }]}]
229
+ { "array": [{ "present": "name" }]}],
230
+ "not_an_array": null
230
231
  }
231
232
  ```
232
233
  You can now validate the fact that each element in the collection has a key which is variant, but a value that has a defined format (the first and last field values are strings).
233
234
 
234
235
  expect_json_types('array_of_hashes.*.*', first: :string, last: :string)
235
236
  expect_json_types('hash_of_hashes.*', first: :string, last: :string)
236
- expect_json_types(optional('lowest_array.*.array.*'), present: :string)
237
- expect_json_types(optional('highest_array.*.array.*'), present: :string)
237
+ expect_json_types(optional('lowest_array.*.array.*'), present: :string)
238
+ expect_json_types(optional('highest_array.*.array.*'), present: :string)
238
239
 
239
240
 
240
241
  ## Development
@@ -1,3 +1,3 @@
1
1
  module Spaceborne
2
- VERSION = '0.1.38'.freeze
2
+ VERSION = '0.1.42'.freeze
3
3
  end
data/lib/spaceborne.rb CHANGED
@@ -156,10 +156,12 @@ module Airborne
156
156
 
157
157
  # Extend airborne's expectations
158
158
  module RequestExpectations
159
+ # class used for holding an optional path
159
160
  class OptionalPathExpectations
160
161
  def initialize(string)
161
162
  @string = string
162
163
  end
164
+
163
165
  def to_s
164
166
  @string.to_s
165
167
  end
@@ -184,7 +186,9 @@ module Airborne
184
186
 
185
187
  def exception_path_adder(args, body)
186
188
  yield
187
- rescue RSpec::Expectations::ExpectationNotMetError, Airborne::ExpectationError => e
189
+ rescue RSpec::Expectations::ExpectationNotMetError,
190
+ ExpectationError,
191
+ Airborne::ExpectationError => e
188
192
  e.message << "\nexpect arguments: #{args}\ndata element: #{body}"
189
193
  raise e
190
194
  end
@@ -225,7 +229,7 @@ module Airborne
225
229
  if data.is_a?(Hash)
226
230
  OptionalHashTypeExpectations.new(data)
227
231
  else
228
- OptionalPathExpectations.new(data)
232
+ Airborne::OptionalPathExpectations.new(data)
229
233
  end
230
234
  end
231
235
  end
@@ -244,7 +248,7 @@ module Airborne
244
248
  end
245
249
 
246
250
  def handle_type(type, path, json, &block)
247
- case type
251
+ case type.to_s
248
252
  when '*'
249
253
  handle_container(json, &block)
250
254
  when '?'
@@ -272,12 +276,17 @@ module Airborne
272
276
  end
273
277
  end
274
278
 
279
+ def shortcut_validation(path, json)
280
+ json.nil? && path.is_a?(Airborne::OptionalPathExpectations)
281
+ end
282
+
275
283
  def get_by_path(path, json, type: false, &block)
276
284
  iterate_path(path) do |parts, part, index|
285
+ return if shortcut_validation(path, json)
286
+
277
287
  if %w[* ?].include?(part.to_s)
278
- ensure_array_or_hash(path, json)
279
288
  type = part
280
- walk_with_path(type, index, path, parts, json, &block) && return if index < parts.length.pred
289
+ walk_with_path(type.to_s, index, path, parts, json, &block) && return if index < parts.length.pred
281
290
 
282
291
  next
283
292
  end
@@ -294,14 +303,20 @@ module Airborne
294
303
  ' from JSON response'
295
304
  end
296
305
 
306
+ def handle_missing_errors(type, path, sub_path, element, &block)
307
+ exception_path_adder({ type: type, path: sub_path }, element) do
308
+ get_by_path(make_sub_path_optional(path, sub_path), element, &block)
309
+ end
310
+ end
311
+
297
312
  def walk_with_path(type, index, path, parts, json, &block)
298
313
  last_error = nil
299
314
  item_count = json.length
300
315
  error_count = 0
301
316
  json.each do |element|
317
+ sub_path = parts[(index.next)...(parts.length)].join('.')
302
318
  begin
303
- sub_path = parts[(index.next)...(parts.length)].join('.')
304
- get_by_path(make_sub_path_optional(path, sub_path), element, &block)
319
+ handle_missing_errors(type, path, sub_path, element, &block)
305
320
  rescue Exception => e
306
321
  last_error = e
307
322
  error_count += 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spaceborne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.38
4
+ version: 0.1.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-20 00:00:00.000000000 Z
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport