spaceborne 0.1.39 → 0.1.43

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47de2c6cb6679f19995cba98157fcf914e181ca5cfc1a7c2be9f011fd593851f
4
- data.tar.gz: 1d598c51e65a741cfa8431c6d603aecca8efe4e6077f4a08f39461a8f1bd980b
3
+ metadata.gz: 19e97691f8756aaeecafb192cd726205e85ba69c98dfc40f1990aaa1b770bf30
4
+ data.tar.gz: 7c3fd96cbd3c684494e7f9a28ab485aac083ddac59ab001d39d5da09ca288bca
5
5
  SHA512:
6
- metadata.gz: 2d08b29b7f93b28aa1f0c1a54b9576483ac0e35d30c42c5c8f9ac62fe157ebea7832175e46df61997398b2f7c3f5f2cbc097b79dcee40b39a84d92e09c3e8167
7
- data.tar.gz: ef1903aa05502a28b612046382a2b06612a6231a2582b6e9555c3f138d54b10fbee6cc2fbc5c0c1f16413f733f34d015c53f837ec1531d677de067d9b80c6e27
6
+ metadata.gz: bb75f8a4d79c6b4cdc76ba22d3daaa556a7d1482a3c0f8c27291bc4686c8f487e3f77539c987ca8a8fccbf573413e09ee0d318281dea561692aa345949d9df1d
7
+ data.tar.gz: 1bdcde6c073c90d29f8fe735fe9776b7122a20279474ceb0bdbdff87e4c153d26daaa50cf731d0314949a07208c9a1842c255986ae6fc3bc88998ac1af519264
@@ -1,3 +1,3 @@
1
1
  module Spaceborne
2
- VERSION = '0.1.39'.freeze
2
+ VERSION = '0.1.43'.freeze
3
3
  end
data/lib/spaceborne.rb CHANGED
@@ -186,7 +186,9 @@ module Airborne
186
186
 
187
187
  def exception_path_adder(args, body)
188
188
  yield
189
- rescue RSpec::Expectations::ExpectationNotMetError, Airborne::ExpectationError => e
189
+ rescue RSpec::Expectations::ExpectationNotMetError,
190
+ ExpectationError,
191
+ Airborne::ExpectationError => e
190
192
  e.message << "\nexpect arguments: #{args}\ndata element: #{body}"
191
193
  raise e
192
194
  end
@@ -227,28 +229,28 @@ module Airborne
227
229
  if data.is_a?(Hash)
228
230
  OptionalHashTypeExpectations.new(data)
229
231
  else
230
- OptionalPathExpectations.new(data)
232
+ Airborne::OptionalPathExpectations.new(data)
231
233
  end
232
234
  end
233
235
  end
234
236
 
235
237
  # extension to handle hash value checking
236
238
  module PathMatcher
237
- def handle_container(json, &block)
239
+ def handle_container(path, json, &block)
238
240
  case json.class.name
239
241
  when 'Array'
240
242
  expect_all(json, &block)
241
243
  when 'Hash'
242
244
  json.each { |k, _v| yield json[k] }
243
245
  else
244
- raise ExpectationError, "expected array or hash, got #{json.class.name}"
246
+ raise ExpectationError, "expected array or hash at #{path}, got #{json.class.name}"
245
247
  end
246
248
  end
247
249
 
248
250
  def handle_type(type, path, json, &block)
249
- case type
251
+ case type.to_s
250
252
  when '*'
251
- handle_container(json, &block)
253
+ handle_container(path, json, &block)
252
254
  when '?'
253
255
  expect_one(path, json, &block)
254
256
  else
@@ -275,19 +277,16 @@ module Airborne
275
277
  end
276
278
 
277
279
  def shortcut_validation(path, json)
278
- return true if json.nil? && path.is_a?(Airborne::OptionalPathExpectations)
279
-
280
- ensure_array_or_hash(path, json)
281
- false
280
+ json.nil? && path.is_a?(Airborne::OptionalPathExpectations)
282
281
  end
283
282
 
284
283
  def get_by_path(path, json, type: false, &block)
285
284
  iterate_path(path) do |parts, part, index|
286
- if %w[* ?].include?(part.to_s)
287
- return if shortcut_validation(path, json)
285
+ return if shortcut_validation(path, json)
288
286
 
287
+ if %w[* ?].include?(part.to_s)
289
288
  type = part
290
- 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
291
290
 
292
291
  next
293
292
  end
@@ -304,14 +303,20 @@ module Airborne
304
303
  ' from JSON response'
305
304
  end
306
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
+
307
312
  def walk_with_path(type, index, path, parts, json, &block)
308
313
  last_error = nil
309
314
  item_count = json.length
310
315
  error_count = 0
311
316
  json.each do |element|
317
+ sub_path = parts[(index.next)...(parts.length)].join('.')
312
318
  begin
313
- sub_path = parts[(index.next)...(parts.length)].join('.')
314
- get_by_path(make_sub_path_optional(path, sub_path), element, &block)
319
+ handle_missing_errors(type, path, sub_path, element, &block)
315
320
  rescue Exception => e
316
321
  last_error = e
317
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.39
4
+ version: 0.1.43
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-23 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport