hops-airborne 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +38 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +12 -0
  6. data/Gemfile +10 -0
  7. data/LICENSE +9 -0
  8. data/README.md +429 -0
  9. data/airborne.gemspec +19 -0
  10. data/lib/airborne/base.rb +82 -0
  11. data/lib/airborne/optional_hash_type_expectations.rb +23 -0
  12. data/lib/airborne/path_matcher.rb +101 -0
  13. data/lib/airborne/rack_test_requester.rb +18 -0
  14. data/lib/airborne/request_expectations.rb +285 -0
  15. data/lib/airborne/rest_client_requester.rb +33 -0
  16. data/lib/airborne.rb +29 -0
  17. data/spec/airborne/base_spec.rb +55 -0
  18. data/spec/airborne/client_requester_spec.rb +42 -0
  19. data/spec/airborne/delete_spec.rb +9 -0
  20. data/spec/airborne/expectations/expect_header_contains_spec.rb +21 -0
  21. data/spec/airborne/expectations/expect_header_spec.rb +21 -0
  22. data/spec/airborne/expectations/expect_json_keys_path_spec.rb +15 -0
  23. data/spec/airborne/expectations/expect_json_keys_spec.rb +21 -0
  24. data/spec/airborne/expectations/expect_json_lambda_spec.rb +9 -0
  25. data/spec/airborne/expectations/expect_json_options_spec.rb +65 -0
  26. data/spec/airborne/expectations/expect_json_path_spec.rb +108 -0
  27. data/spec/airborne/expectations/expect_json_regex_spec.rb +33 -0
  28. data/spec/airborne/expectations/expect_json_sizes_spec.rb +33 -0
  29. data/spec/airborne/expectations/expect_json_spec.rb +27 -0
  30. data/spec/airborne/expectations/expect_json_types_date_spec.rb +52 -0
  31. data/spec/airborne/expectations/expect_json_types_lambda_spec.rb +9 -0
  32. data/spec/airborne/expectations/expect_json_types_optional_spec.rb +15 -0
  33. data/spec/airborne/expectations/expect_json_types_options_spec.rb +59 -0
  34. data/spec/airborne/expectations/expect_json_types_path_spec.rb +65 -0
  35. data/spec/airborne/expectations/expect_json_types_spec.rb +85 -0
  36. data/spec/airborne/expectations/expect_status_spec.rb +23 -0
  37. data/spec/airborne/head_spec.rb +10 -0
  38. data/spec/airborne/options_spec.rb +10 -0
  39. data/spec/airborne/patch_spec.rb +9 -0
  40. data/spec/airborne/path_spec.rb +34 -0
  41. data/spec/airborne/post_spec.rb +17 -0
  42. data/spec/airborne/put_spec.rb +9 -0
  43. data/spec/airborne/rack/rack_sinatra_spec.rb +43 -0
  44. data/spec/spec_helper.rb +14 -0
  45. data/spec/stub_helper.rb +45 -0
  46. data/spec/test_responses/array_of_types.json +9 -0
  47. data/spec/test_responses/array_of_values.json +5 -0
  48. data/spec/test_responses/array_response.json +5 -0
  49. data/spec/test_responses/array_with_index.json +6 -0
  50. data/spec/test_responses/array_with_nested.json +16 -0
  51. data/spec/test_responses/array_with_nested_bad_data.json +15 -0
  52. data/spec/test_responses/array_with_partial_nested.json +12 -0
  53. data/spec/test_responses/date_is_null_response.json +3 -0
  54. data/spec/test_responses/date_response.json +3 -0
  55. data/spec/test_responses/hash_property.json +3 -0
  56. data/spec/test_responses/invalid_get.json +1 -0
  57. data/spec/test_responses/invalid_json.json +1 -0
  58. data/spec/test_responses/numeric_property.json +6 -0
  59. data/spec/test_responses/simple_delete.json +4 -0
  60. data/spec/test_responses/simple_get.json +5 -0
  61. data/spec/test_responses/simple_json.json +5 -0
  62. data/spec/test_responses/simple_nested_path.json +12 -0
  63. data/spec/test_responses/simple_patch.json +4 -0
  64. data/spec/test_responses/simple_path_get.json +8 -0
  65. data/spec/test_responses/simple_post.json +4 -0
  66. data/spec/test_responses/simple_put.json +4 -0
  67. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 44bc2ba84798ddd8b609025a5d1c2450c433dcae7900b0dafaa9004cbbf18dbd
4
+ data.tar.gz: c8fb9237ae5b032175d160ad67aee1f44e8ebab552633ca4729c273e2f36c50e
5
+ SHA512:
6
+ metadata.gz: e9edd20e17de87067dc2f9930fd65de1b967aba8d73164b7887509536a5355e555ced9be786f23a075c73d56c9b061560036d0c5fdf85d6034e6d02e68c49c44
7
+ data.tar.gz: fc51c93e60ebcd57b092d2b2bf1811e57d25d98184948e2d26b80842910c7a9336de35e144bca3b2337f8d82df9572e1afc8f5eb1f22ebabcbde323ca0e4afd2
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ .idea
2
+ .ruby-*
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+ .idea
38
+ .DS_store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fd -c
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ - 2.3.1
6
+ - 2.4.1
7
+
8
+ script: bundle exec rspec spec
9
+ before_install:
10
+ - gem update --system
11
+ - gem --version
12
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'coveralls', require: false
6
+
7
+ group :test do
8
+ gem 'webmock'
9
+ gem 'sinatra'
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2014 brooklyndev, sethpollack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,429 @@
1
+ # Airborne
2
+
3
+ [![airborne travis](http://img.shields.io/travis/brooklynDev/airborne.svg?branch=master&style=flat-square)](https://travis-ci.org/brooklynDev/airborne)
4
+ [![airborne coveralls](http://img.shields.io/coveralls/brooklynDev/airborne/master.svg?style=flat-square)](https://coveralls.io/r/brooklynDev/airborne?branch=master)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/brooklynDev/airborne.svg?style=flat-square)](https://codeclimate.com/github/brooklynDev/airborne)
6
+ [![airborne gem version](http://img.shields.io/gem/v/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)
7
+ [![airbore gem downloads](http://img.shields.io/gem/dt/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)
8
+ [![airborne gem stable downloads](http://img.shields.io/gem/dv/airborne/stable.svg?style=flat-square)](http://rubygems.org/gems/airborne)
9
+
10
+ RSpec driven API testing framework
11
+
12
+ ## Looking for Project Maintainers
13
+ I am looking for project maintainers to help keep airborne up to date and bug-free while avoiding feature creep and maintaining backwards compatibility.
14
+
15
+ Comment [here](https://github.com/brooklynDev/airborne/issues/134) if you would like to help out.
16
+
17
+ ## Installation
18
+
19
+ Install Airborne:
20
+ ```shell
21
+ $ gem install airborne
22
+ ```
23
+ Or add it to your Gemfile:
24
+ ```ruby
25
+ gem 'airborne'
26
+ ```
27
+ ## Creating Tests
28
+
29
+ ```ruby
30
+ require 'airborne'
31
+
32
+ describe 'sample spec' do
33
+ it 'should validate types' do
34
+ get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
35
+ expect_json_types(name: :string)
36
+ end
37
+
38
+ it 'should validate values' do
39
+ get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
40
+ expect_json(name: 'John Doe')
41
+ end
42
+ end
43
+ ```
44
+
45
+ When calling expect_json_types, these are the valid types that can be tested against:
46
+
47
+ * `:int` or `:integer`
48
+ * `:float`
49
+ * `:bool` or `:boolean`
50
+ * `:string`
51
+ * `:date`
52
+ * `:object`
53
+ * `:null`
54
+ * `:array`
55
+ * `:array_of_integers` or `:array_of_ints`
56
+ * `:array_of_floats`
57
+ * `:array_of_strings`
58
+ * `:array_of_booleans` or `:array_of_bools`
59
+ * `:array_of_objects`
60
+ * `:array_of_arrays`
61
+
62
+ If the properties are optional and may not appear in the response, you can append `_or_null` to the types above.
63
+
64
+ ```ruby
65
+ describe 'sample spec' do
66
+ it 'should validate types' do
67
+ get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } or { "name" : "John Doe", "age" : 45 }
68
+ expect_json_types(name: :string, age: :int_or_null)
69
+ end
70
+ end
71
+ ```
72
+
73
+ Additionally, if an entire object could be null, but you'd still want to test the types if it does exist, you can wrap the expectations in a call to `optional`:
74
+
75
+ ```ruby
76
+ it 'should allow optional nested hash' do
77
+ get '/simple_path_get' #may or may not return coordinates
78
+ expect_json_types('address.coordinates', optional(latitude: :float, longitude: :float))
79
+ end
80
+ ```
81
+
82
+ Additionally, when calling `expect_json`, you can provide a regex pattern in a call to `regex`:
83
+
84
+ ```ruby
85
+ describe 'sample spec' do
86
+ it 'should validate types' do
87
+ get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
88
+ expect_json(name: regex("^John"))
89
+ end
90
+ end
91
+ ```
92
+
93
+ When calling `expect_json` or `expect_json_types`, you can optionally provide a block and run your own `rspec` expectations:
94
+
95
+ ```ruby
96
+ describe 'sample spec' do
97
+ it 'should validate types' do
98
+ get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
99
+ expect_json(name: -> (name){ expect(name.length).to eq(8) })
100
+ end
101
+ end
102
+ ```
103
+
104
+ Calling `expect_json_sizes` actually make use of the above feature and call `expect_json` under the hood:
105
+
106
+ ```ruby
107
+ describe 'sample spec' do
108
+ it 'should validate types' do
109
+ get 'http://example.com/api/v1/simple_get_collection' #json api that returns { "ids" : [1, 2, 3, 4] }
110
+ expect_json_sizes(ids: 4)
111
+ end
112
+ end
113
+ ```
114
+
115
+ ## Making requests
116
+
117
+ Airborne uses `rest_client` to make the HTTP request, and supports all HTTP verbs. When creating a test, you can call any of the following methods: `get`, `post`, `put`, `patch`, `delete`, `head`, `options`. This will then give you access the following properties:
118
+
119
+ * `response` - The HTTP response returned from the request
120
+ * `headers` - A symbolized hash of the response headers returned by the request
121
+ * `body` - The raw HTTP body returned from the request
122
+ * `json_body` - A symbolized hash representation of the JSON returned by the request
123
+
124
+ For example:
125
+
126
+ ```ruby
127
+ it 'should validate types' do
128
+ get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
129
+ name = json_body[:name] #name will equal "John Doe"
130
+ body_as_string = body
131
+ end
132
+ ```
133
+
134
+ When calling any of the methods above, you can pass request headers to be used.
135
+
136
+ ```ruby
137
+ get 'http://example.com/api/v1/my_api', { 'x-auth-token' => 'my_token' }
138
+ ```
139
+
140
+ For requests that require a body (`post`, `put`, `patch`) you can pass the body as a hash as well:
141
+
142
+ ```ruby
143
+ post 'http://example.com/api/v1/my_api', { :name => 'John Doe' }, { 'x-auth-token' => 'my_token' }
144
+ ```
145
+
146
+ For requests that require Query params you can pass a params hash into headers.
147
+
148
+ ```ruby
149
+ post 'http://example.com/api/v1/my_api', { }, { 'params' => {'param_key' => 'param_value' } }
150
+ ```
151
+
152
+ ## Testing Rack Applications
153
+
154
+ If you have an existing Rack application like `sinatra` or `grape` you can run Airborne against your application and test without actually having a server running. To do that, just specify your rack application in your Airborne configuration:
155
+
156
+ ```ruby
157
+ Airborne.configure do |config|
158
+ config.rack_app = MySinatraApp
159
+ end
160
+ ```
161
+
162
+ Under the covers, Airborne uses [rack-test](https://github.com/brynary/rack-test) to make the requests.
163
+
164
+ ## Rails Applications
165
+
166
+ If you're testing an API you've written in Rails, Airborne plays along with `rspec-rails`:
167
+
168
+
169
+ ```ruby
170
+ require 'rails_helper'
171
+
172
+ RSpec.describe HomeController, :type => :controller do
173
+ describe 'GET index' do
174
+ it 'returns correct types' do
175
+ get :index, :format => 'json' #if your route responds to both html and json
176
+ expect_json_types(foo: :string)
177
+ end
178
+ end
179
+ end
180
+ ```
181
+
182
+ ## API
183
+
184
+ * `expect_json_types` - Tests the types of the JSON property values returned
185
+ * `expect_json` - Tests the values of the JSON property values returned
186
+ * `expect_json_keys` - Tests the existence of the specified keys in the JSON object
187
+ * `expect_json_sizes` - Tests the sizes of the JSON property values returned, also test if the values are arrays
188
+ * `expect_status` - Tests the HTTP status code returned
189
+ * `expect_header` - Tests for a specified header in the response
190
+ * `expect_header_contains` - Partial match test on a specified header
191
+
192
+ ## Path Matching
193
+
194
+ When calling `expect_json_types`, `expect_json`, `expect_json_keys` or `expect_json_sizes` you can optionally specify a path as a first parameter.
195
+
196
+ For example, if our API returns the following JSON:
197
+
198
+ ```json
199
+ {
200
+ "name": "Alex",
201
+ "address": {
202
+ "street": "Area 51",
203
+ "city": "Roswell",
204
+ "state": "NM",
205
+ "coordinates": {
206
+ "latitude": 33.3872,
207
+ "longitude": 104.5281
208
+ }
209
+ }
210
+ }
211
+ ```
212
+
213
+ This test would only test the address object:
214
+
215
+ ```ruby
216
+ describe 'path spec' do
217
+ it 'should allow simple path and verify only that path' do
218
+ get 'http://example.com/api/v1/simple_path_get'
219
+ expect_json_types('address', street: :string, city: :string, state: :string, coordinates: :object)
220
+ #or this
221
+ expect_json_types('address', street: :string, city: :string, state: :string, coordinates: { latitude: :float, longitude: :float })
222
+ end
223
+ end
224
+ ```
225
+ Or, to test the existence of specific keys:
226
+
227
+ ```ruby
228
+ it 'should allow nested paths' do
229
+ get 'http://example.com/api/v1/simple_path_get'
230
+ expect_json_keys('address', [:street, :city, :state, :coordinates])
231
+ end
232
+ ```
233
+
234
+ Alternativley, if we only want to test `coordinates` we can dot into just the `coordinates`:
235
+
236
+ ```ruby
237
+ it 'should allow nested paths' do
238
+ get 'http://example.com/api/v1/simple_path_get'
239
+ expect_json('address.coordinates', latitude: 33.3872, longitude: 104.5281)
240
+ end
241
+ ```
242
+
243
+ When dealing with `arrays`, we can optionally test all (`*`) or a single (`?` - any, `0` - index) element of the array:
244
+
245
+ Given the following JSON:
246
+
247
+ ```json
248
+ {
249
+ "cars": [
250
+ {
251
+ "make": "Tesla",
252
+ "model": "Model S"
253
+ },
254
+ {
255
+ "make": "Lamborghini",
256
+ "model": "Aventador"
257
+ }
258
+ ]
259
+ }
260
+ ```
261
+
262
+ We can test against just the first car like this:
263
+
264
+ ```ruby
265
+ it 'should index into array and test against specific element' do
266
+ get '/array_api'
267
+ expect_json('cars.0', make: 'Tesla', model: 'Model S')
268
+ end
269
+ ```
270
+
271
+ To test the types of all elements in the array:
272
+
273
+ ```ruby
274
+ it 'should test all elements of the array' do
275
+ get 'http://example.com/api/v1/array_api'
276
+ expect_json('cars.?', make: 'Tesla', model: 'Model S') # tests that one car in array matches the tesla
277
+ expect_json_types('cars.*', make: :string, model: :string) # tests all cars in array for make and model of type string
278
+ end
279
+ ```
280
+
281
+ `*` and `?` work for nested arrays as well. Given the following JSON:
282
+
283
+ ```json
284
+ {
285
+ "cars": [
286
+ {
287
+ "make": "Tesla",
288
+ "model": "Model S",
289
+ "owners": [
290
+ {
291
+ "name": "Bart Simpson"
292
+ }
293
+ ]
294
+ },
295
+ {
296
+ "make": "Lamborghini",
297
+ "model": "Aventador",
298
+ "owners": [
299
+ {
300
+ "name": "Peter Griffin"
301
+ }
302
+ ]
303
+ }
304
+ ]
305
+ }
306
+ ```
307
+
308
+ ===
309
+
310
+ ```ruby
311
+ it 'should check all nested arrays for specified elements' do
312
+ get 'http://example.com/api/v1/array_with_nested'
313
+ expect_json_types('cars.*.owners.*', name: :string)
314
+ end
315
+ ```
316
+
317
+ ## Dates
318
+
319
+ JSON has no support for dates, however airborne gives you the ability to check for dates using the following. For `expect_json_types` you would use it as you would for any of the other types:
320
+
321
+ ```ruby
322
+ it 'should verify date type' do
323
+ get '/get_date' #api that returns {createdAt: "Mon Oct 20 2014 16:10:42 GMT-0400 (EDT)"}
324
+ expect_json_types(createdAt: :date)
325
+ end
326
+ ```
327
+ However if you want to check the actual date data with `expect_json`, you need to call the `date` function:
328
+
329
+ ```ruby
330
+ it 'should verify correct date value' do
331
+ get '/get_date' #api that returns {createdAt: "Mon Oct 20 2014 16:10:42 GMT-0400 (EDT)"}
332
+ prev_day = DateTime.new(2014,10,19)
333
+ next_day = DateTime.new(2014,10,21)
334
+ #within the date callback, you can use regular RSpec expectations that work with dates
335
+ expect_json(createdAt: date { |value| expect(value).to be_between(prev_day, next_day) })
336
+ end
337
+ ```
338
+
339
+ ## Configuration
340
+
341
+ When setting up Airborne, you can call `configure` just like you would with `rspec`:
342
+
343
+ ```ruby
344
+ #config is the RSpec configuration and can be used just like it
345
+ Airborne.configure do |config|
346
+ config.include MyModule
347
+ end
348
+ ```
349
+
350
+ Additionally, you can specify a `base_url` and default `headers` to be used on every request (unless overridden in the actual request):
351
+
352
+ ```ruby
353
+ Airborne.configure do |config|
354
+ config.base_url = 'http://example.com/api/v1'
355
+ config.headers = { 'x-auth-token' => 'my_token' }
356
+ end
357
+
358
+ describe 'spec' do
359
+ it 'now we no longer need the full url' do
360
+ get '/simple_get'
361
+ expect_json_types(name: :string)
362
+ end
363
+ end
364
+ ```
365
+
366
+ You can also control the strictness of `expect_json` and `expect_json_types` with the global settings `match_expected_default` and `match_actual_default` like this.
367
+
368
+ ```ruby
369
+ Airborne.configure do |config|
370
+ config.match_expected_default = true
371
+ config.match_actual_default = false
372
+ end
373
+ ```
374
+
375
+ `match_expected_default` requires all the keys in the expected JSON are present in the response.
376
+ `match_actual_default` requires that the keys in the response are tested in the expected Hash.
377
+
378
+ So you can do the following combinations:
379
+
380
+ `match_expected_default=false`, `match_actual_default=false` - check only intersection
381
+ `match_expected_default=false`, `match_actual_default=true` - raise on extra key in response
382
+ `match_expected_default=true`, `match_actual_default=false` - raise on missing key in response
383
+ `match_expected_default=true`, `match_actual_default=true` - expect exact match
384
+
385
+
386
+ Airborne sets `match_expected_default` to `true` and `match_actual_default` to `false` by default.
387
+
388
+ You can use the `match_expected` and `match_actual` settings to override your global defaults in test blocks like this.
389
+
390
+ ```ruby
391
+ describe 'test something', match_expected: true, match_actual: false do
392
+ end
393
+ ```
394
+
395
+ OR
396
+
397
+ ```ruby
398
+ describe 'test something' do
399
+ Airborne.configuration.match_expected = true
400
+ Airborne.configuration.match_actual = false
401
+ end
402
+ ```
403
+
404
+ ## Run it from the CLI
405
+
406
+ ```shell
407
+ $ cd your/project
408
+ $ rspec spec
409
+ ```
410
+ ## Authors
411
+ * [Seth Pollack](https://github.com/sethpollack)
412
+ * [Alex Friedman](https://github.com/brooklynDev)
413
+
414
+ ## Contributors
415
+ https://github.com/brooklynDev/airborne/graphs/contributors
416
+
417
+ Inspired by [frisby.js](https://github.com/vlucas/frisby)
418
+
419
+ ## License
420
+
421
+ The MIT License
422
+
423
+ Copyright (c) 2014 [brooklyndev](https://github.com/brooklynDev), [sethpollack](https://github.com/sethpollack)
424
+
425
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
426
+
427
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
428
+
429
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/airborne.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ require 'date'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'hops-airborne'
5
+ s.version = '0.2.15'
6
+ s.date = Date.today.to_s
7
+ s.summary = 'RSpec driven API testing framework - LogicalClocks maintained fork'
8
+ s.authors = ['Alex Friedman', 'Seth Pollack', 'Fabio Buso']
9
+ s.email = ['fabio@logicalclocks.com']
10
+ s.require_paths = ['lib']
11
+ s.files = `git ls-files`.split("\n")
12
+ s.license = 'MIT'
13
+ s.add_runtime_dependency 'rspec', '~> 3.1'
14
+ s.add_runtime_dependency 'rest-client', '< 3.0', '>= 1.7.3'
15
+ s.add_runtime_dependency 'rack-test', '~> 0.6', '>= 0.6.2'
16
+ s.add_runtime_dependency 'rack'
17
+ s.add_runtime_dependency 'activesupport'
18
+ s.add_development_dependency 'webmock', '~> 0'
19
+ end
@@ -0,0 +1,82 @@
1
+ require 'json'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
+
5
+ module Airborne
6
+ class InvalidJsonError < StandardError; end
7
+
8
+ include RequestExpectations
9
+
10
+ attr_reader :response, :headers, :body
11
+
12
+ def self.configure
13
+ RSpec.configure do |config|
14
+ yield config
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ if !Airborne.configuration.requester_module.nil?
20
+ base.send(:include, Airborne.configuration.requester_module)
21
+ elsif !Airborne.configuration.rack_app.nil?
22
+ base.send(:include, RackTestRequester)
23
+ else
24
+ base.send(:include, RestClientRequester)
25
+ end
26
+ end
27
+
28
+ def self.configuration
29
+ RSpec.configuration
30
+ end
31
+
32
+ def get(url, headers = nil)
33
+ @response = make_request(:get, url, headers: headers)
34
+ end
35
+
36
+ def post(url, post_body = nil, headers = nil)
37
+ @response = make_request(:post, url, body: post_body, headers: headers)
38
+ end
39
+
40
+ def patch(url, patch_body = nil, headers = nil)
41
+ @response = make_request(:patch, url, body: patch_body, headers: headers)
42
+ end
43
+
44
+ def put(url, put_body = nil, headers = nil)
45
+ @response = make_request(:put, url, body: put_body, headers: headers)
46
+ end
47
+
48
+ def delete(url, delete_body = nil, headers = nil)
49
+ @response = make_request(:delete, url, body: delete_body, headers: headers)
50
+ end
51
+
52
+ def head(url, headers = nil)
53
+ @response = make_request(:head, url, headers: headers)
54
+ end
55
+
56
+ def options(url, headers = nil)
57
+ @response = make_request(:options, url, headers: headers)
58
+ end
59
+
60
+ def response
61
+ @response
62
+ end
63
+
64
+ def headers
65
+ HashWithIndifferentAccess.new(response.headers)
66
+ end
67
+
68
+ def body
69
+ response.body
70
+ end
71
+
72
+ def json_body
73
+ JSON.parse(response.body, symbolize_names: true) rescue fail InvalidJsonError, 'Api request returned invalid json'
74
+ end
75
+
76
+ private
77
+
78
+ def get_url(url)
79
+ base = Airborne.configuration.base_url || ''
80
+ base + url
81
+ end
82
+ end
@@ -0,0 +1,23 @@
1
+ module Airborne
2
+ class OptionalHashTypeExpectations
3
+ include Enumerable
4
+ attr_accessor :hash
5
+ def initialize(hash)
6
+ @hash = hash
7
+ end
8
+
9
+ def each
10
+ @hash.each do|k, v|
11
+ yield(k, v)
12
+ end
13
+ end
14
+
15
+ def [](val)
16
+ @hash[val]
17
+ end
18
+
19
+ def keys
20
+ @hash.keys
21
+ end
22
+ end
23
+ end