spaceborne 0.1.22 → 0.1.27

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: 23b0e8ffb074901b03f8e7d2d67cbf294108c2559fabef084ac7c2949e85f087
4
- data.tar.gz: bb2cbbb92cdbc25782fbcb65a80c6ab4a8ac61e6fec0c3580ea39ba5e2fa7093
3
+ metadata.gz: 65594555f221b6872a3879ff3b950fb367dfe58e59e5fa6a783adaef06500b14
4
+ data.tar.gz: 2f2fcd333db9cccfd7123344a7fbdc64d6eef5881b1a6753faaa27187e5520e0
5
5
  SHA512:
6
- metadata.gz: 4f8e39ba862e2b7877061b3dd34f6c33fb8f36c966098ce8002c4575c9d2d926bcb4c03dbb38d309d626dbecb96617f0eb161b86c29a17af0844be15e4b79e8c
7
- data.tar.gz: c96f5aa29e78e05d0f384bdd938fb33610719fdfe29177a38c022771e421d306d8d5fdc38ec3a38493c0b10e3dd1ed86c408ad09b07d6eac270364ce0e06be1b
6
+ metadata.gz: 7dbff4868d6078d249e9305a09bd9538a79e6aada32de8bcf54215f4abef7a3b815086ca968ca43b7a9ad813bf048cc33d5513bc62e981befcfaf77d43482a3a
7
+ data.tar.gz: 0f8252b4ff5715d6abf9b34ba85de55073eb53dee854a2420e81e7f20fdf93ad18bdff1bd39785595e77a2601402e8fc6bd3fbf8945ffb4cb3816bfe9176493f
@@ -1 +1 @@
1
- ruby-2.4.1
1
+ ruby-2.5.5
@@ -33,6 +33,7 @@ module Spaceborne
33
33
 
34
34
  def response_body
35
35
  return '' if response.request.method.casecmp('head').zero?
36
+
36
37
  str = if json?(response.headers)
37
38
  " JSON_BODY\n#{JSON.pretty_generate(json_body)}\n"
38
39
  else
@@ -50,6 +51,7 @@ module Spaceborne
50
51
  yield
51
52
  rescue Exception => e
52
53
  raise e unless response
54
+
53
55
  e.message << request_info
54
56
  raise e
55
57
  end
@@ -87,17 +89,20 @@ module Airborne
87
89
  headers = base_headers.merge(options[:headers] || {})
88
90
  headers[:no_restclient_headers] = true
89
91
  return headers unless local[:is_hash]
92
+
90
93
  headers.delete('Content-Type') if options[:nonjson_data]
91
94
  headers
92
95
  end
93
96
 
94
97
  def handle_proxy(_options, local)
95
98
  return unless local[:proxy]
99
+
96
100
  RestClient.proxy = local[:proxy]
97
101
  end
98
102
 
99
103
  def calc_body(options, local)
100
104
  return '' unless options[:body]
105
+
101
106
  if local[:nonjson_data] || !local[:is_hash]
102
107
  options[:body]
103
108
  else
@@ -113,21 +118,32 @@ module Airborne
113
118
  end
114
119
  end
115
120
 
116
- def make_request(method, url, options = {})
121
+ def pre_request(options)
117
122
  @json_body = nil
118
123
  local_options = split_options(options)
119
124
  handle_proxy(options, local_options)
120
125
  hdrs = calc_headers(options, local_options)
121
126
  @request_body = calc_body(options, local_options)
122
- send_restclient(method, get_url(url), @request_body, hdrs)
127
+ [hdrs, @request_body]
128
+ end
129
+
130
+ def make_request(method, url, options = {})
131
+ hdrs, body = pre_request(options)
132
+ send_restclient(method, get_url(url), body, hdrs)
133
+ rescue RestClient::ServerBrokeConnection => e
134
+ raise e
123
135
  rescue RestClient::Exception => e
124
- e.response
136
+ if [301, 302].include?(e.response.code)
137
+ e.response.follow_redirection
138
+ else
139
+ e.response
140
+ end
125
141
  end
126
142
 
127
143
  private
128
144
 
129
145
  def base_headers
130
- { "Content-Type" => 'application/json' }
146
+ { 'Content-Type' => 'application/json' }
131
147
  .merge(Airborne.configuration.headers || {})
132
148
  end
133
149
  end
@@ -144,16 +160,16 @@ module Airborne
144
160
  end
145
161
  end
146
162
 
147
- def exception_path_adder(path)
163
+ def exception_path_adder(args)
148
164
  yield
149
165
  rescue Airborne::ExpectationError => e
150
- e.message << " at location #{path}"
166
+ e.message << "expect arguments: #{args}"
151
167
  raise e
152
168
  end
153
169
 
154
170
  def expect_json_types(*args)
155
171
  call_with_relative_path(json_body, args) do |param, body|
156
- exception_path_adder(args[0]) do
172
+ exception_path_adder(args) do
157
173
  expect_json_types_impl(param, body)
158
174
  end
159
175
  end
@@ -161,7 +177,7 @@ module Airborne
161
177
 
162
178
  def expect_json(*args)
163
179
  call_with_relative_path(json_body, args) do |param, body|
164
- exception_path_adder(args[0]) do
180
+ exception_path_adder(args) do
165
181
  expect_json_impl(param, body)
166
182
  end
167
183
  end
@@ -169,7 +185,7 @@ module Airborne
169
185
 
170
186
  def expect_header_types(*args)
171
187
  call_with_relative_path(response.headers, args) do |param, body|
172
- exception_path_adder(args[0]) do
188
+ exception_path_adder(args) do
173
189
  expect_json_types_impl(param, body)
174
190
  end
175
191
  end
@@ -177,7 +193,7 @@ module Airborne
177
193
 
178
194
  def expect_header(*args)
179
195
  call_with_relative_path(response.headers, args) do |param, body|
180
- exception_path_adder(args[0]) do
196
+ exception_path_adder(args) do
181
197
  expect_json_impl(param, body)
182
198
  end
183
199
  end
@@ -186,44 +202,60 @@ module Airborne
186
202
 
187
203
  # extension to handle hash value checking
188
204
  module PathMatcher
189
- def get_by_path(path, json, &block)
205
+ def do_process_json(part, json)
206
+ json = process_json(part, json)
207
+ rescue StandardError
208
+ raise PathError,
209
+ "Expected #{json.class}\nto be an object with property #{part}"
210
+ end
211
+
212
+ def handle_container(json, &block)
213
+ case json.class.name
214
+ when 'Array'
215
+ expect_all(json, &block)
216
+ when 'Hash'
217
+ json.each do |k, _v|
218
+ yield json[k]
219
+ end
220
+ end
221
+ end
222
+
223
+ def handle_type(type, path, json, &block)
224
+ if type == '*'
225
+ handle_container(json, &block)
226
+ elsif type == '?'
227
+ expect_one(path, json, &block)
228
+ else
229
+ yield json
230
+ end
231
+ end
232
+
233
+ def iterate_path(path)
190
234
  raise PathError, "Invalid Path, contains '..'" if /\.\./ =~ path
191
- type = false
235
+
192
236
  parts = path.to_s.split('.')
193
237
  parts.each_with_index do |part, index|
238
+ yield(parts, part, index)
239
+ end
240
+ end
241
+
242
+ def get_by_path(path, json, type = false, &block)
243
+ iterate_path(path) do |parts, part, index|
194
244
  if %w[* ?].include?(part)
195
245
  ensure_array_or_hash(path, json)
196
246
  type = part
197
- if index < parts.length.pred
198
- walk_with_path(type, index, path, parts, json, &block) && return
199
- end
247
+ walk_with_path(type, index, path, parts, json, &block) && return if index < parts.length.pred
248
+
200
249
  next
201
250
  end
202
- begin
203
- json = process_json(part, json)
204
- rescue StandardError
205
- raise PathError,
206
- "Expected #{json.class}\nto be an object with property #{part}"
207
- end
208
- end
209
- if type == '*'
210
- case json.class.name
211
- when 'Array'
212
- expect_all(json, &block)
213
- when 'Hash'
214
- json.each do |k, _v|
215
- yield json[k]
216
- end
217
- end
218
- elsif type == '?'
219
- expect_one(path, json, &block)
220
- else
221
- yield json
251
+ json = do_process_json(part, json)
222
252
  end
253
+ handle_type(type, path, json, &block)
223
254
  end
224
255
 
225
256
  def ensure_array_or_hash(path, json)
226
257
  return if json.class == Array || json.class == Hash
258
+
227
259
  raise RSpec::Expectations::ExpectationNotMetError,
228
260
  "Expected #{path} to be array or hash, got #{json.class}"\
229
261
  ' from JSON response'
@@ -1,3 +1,3 @@
1
1
  module Spaceborne
2
- VERSION = '0.1.22'.freeze
2
+ VERSION = '0.1.27'.freeze
3
3
  end
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'webmock', '~> 0'
31
31
 
32
32
  spec.add_development_dependency 'byebug', '~> 10.0.2'
33
- spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rake', '~> 12.3.3'
34
34
  end
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.22
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-02 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -154,14 +154,14 @@ dependencies:
154
154
  requirements:
155
155
  - - "~>"
156
156
  - !ruby/object:Gem::Version
157
- version: '10.0'
157
+ version: 12.3.3
158
158
  type: :development
159
159
  prerelease: false
160
160
  version_requirements: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - "~>"
163
163
  - !ruby/object:Gem::Version
164
- version: '10.0'
164
+ version: 12.3.3
165
165
  description: Extends brooklynDev/airborne
166
166
  email:
167
167
  - keithrw@comcast.net
@@ -185,7 +185,7 @@ homepage: https://github.com/keithrw54/spaceborne.git
185
185
  licenses:
186
186
  - MIT
187
187
  metadata: {}
188
- post_install_message:
188
+ post_install_message:
189
189
  rdoc_options: []
190
190
  require_paths:
191
191
  - lib
@@ -200,9 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.7.9
205
- signing_key:
203
+ rubygems_version: 3.0.8
204
+ signing_key:
206
205
  specification_version: 4
207
206
  summary: Gem supporting API testing
208
207
  test_files: []