airborne 0.1.19 → 0.1.20
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 +4 -4
- data/README.md +24 -24
- data/airborne.gemspec +1 -1
- data/lib/airborne/base.rb +2 -2
- data/spec/airborne/delete_spec.rb +1 -1
- data/spec/stub_helper.rb +3 -2
- data/spec/test_responses/simple_delete.json +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e39a27825d4bd6356a68d61d5298b9df7efc78
|
4
|
+
data.tar.gz: a092d5c4e6ea8a77e5ffd44507bd30809fc1d918
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07884c5bf421f27b6c1e5f6b24d90468b2148b6cff688bd36569445259f200311d95b3ca17118af96a96458f7ef2c04462b5e3aa9efee854036fb08832bd7622
|
7
|
+
data.tar.gz: c358814cc80983f0895eca497b37602f8123ea300f7ff8814d1559fc8cf7e7f2c99adc2c1dc9af5b94e4e114341ff07de11a43f0edd01e331ed14069cfc3b518
|
data/README.md
CHANGED
@@ -27,12 +27,12 @@ require 'airborne'
|
|
27
27
|
describe 'sample spec' do
|
28
28
|
it 'should validate types' do
|
29
29
|
get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
|
30
|
-
expect_json_types(
|
30
|
+
expect_json_types(name: :string)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should validate values' do
|
34
34
|
get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
|
35
|
-
expect_json(
|
35
|
+
expect_json(name: 'John Doe')
|
36
36
|
end
|
37
37
|
end
|
38
38
|
```
|
@@ -60,7 +60,7 @@ If the properties are optional and may not appear in the response, you can appen
|
|
60
60
|
describe 'sample spec' do
|
61
61
|
it 'should validate types' do
|
62
62
|
get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } or { "name" : "John Doe", "age" : 45 }
|
63
|
-
expect_json_types(
|
63
|
+
expect_json_types(name: :string, age: :int_or_null)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
```
|
@@ -70,7 +70,7 @@ Additionally, if an entire object could be null, but you'd still want to test th
|
|
70
70
|
```ruby
|
71
71
|
it 'should allow optional nested hash' do
|
72
72
|
get '/simple_path_get' #may or may not return coordinates
|
73
|
-
expect_json_types(
|
73
|
+
expect_json_types('address.coordinates', optional(latitude: :float, longitude: :float))
|
74
74
|
end
|
75
75
|
```
|
76
76
|
|
@@ -80,7 +80,7 @@ Additionally, when calling `expect_json`, you can provide a regex pattern in a c
|
|
80
80
|
describe 'sample spec' do
|
81
81
|
it 'should validate types' do
|
82
82
|
get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
|
83
|
-
expect_json(
|
83
|
+
expect_json(name: regex("^John"))
|
84
84
|
end
|
85
85
|
end
|
86
86
|
```
|
@@ -91,7 +91,7 @@ When calling `expect_json` or `expect_json_types`, you can optionally provide a
|
|
91
91
|
describe 'sample spec' do
|
92
92
|
it 'should validate types' do
|
93
93
|
get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" }
|
94
|
-
expect_json(
|
94
|
+
expect_json(name: -> (name){ expect(name.length).to eq(8) })
|
95
95
|
end
|
96
96
|
end
|
97
97
|
```
|
@@ -102,7 +102,7 @@ Calling `expect_json_sizes` actually make use of the above feature and call `exp
|
|
102
102
|
describe 'sample spec' do
|
103
103
|
it 'should validate types' do
|
104
104
|
get 'http://example.com/api/v1/simple_get_collection' #json api that returns { "ids" : [1, 2, 3, 4] }
|
105
|
-
expect_json_sizes(
|
105
|
+
expect_json_sizes(ids: 4)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
```
|
@@ -129,19 +129,19 @@ end
|
|
129
129
|
When calling any of the methods above, you can pass request headers to be used.
|
130
130
|
|
131
131
|
```ruby
|
132
|
-
get 'http://example.com/api/v1/my_api', {'x-auth-token' => 'my_token'}
|
132
|
+
get 'http://example.com/api/v1/my_api', { 'x-auth-token' => 'my_token' }
|
133
133
|
```
|
134
134
|
|
135
135
|
For requests that require a body (`post`, `put`, `patch`) you can pass the body as a hash as well:
|
136
136
|
|
137
137
|
```ruby
|
138
|
-
post 'http://example.com/api/v1/my_api', {:name => 'John Doe'}, {'x-auth-token' => 'my_token'}
|
138
|
+
post 'http://example.com/api/v1/my_api', { :name => 'John Doe' }, { 'x-auth-token' => 'my_token' }
|
139
139
|
```
|
140
140
|
|
141
141
|
For requests that require Query params you can pass a params hash into headers.
|
142
142
|
|
143
143
|
```ruby
|
144
|
-
post 'http://example.com/api/v1/my_api', {}, {'params' => {'param_key' => 'param_value'}
|
144
|
+
post 'http://example.com/api/v1/my_api', { }, { 'params' => {'param_key' => 'param_value' }
|
145
145
|
```
|
146
146
|
|
147
147
|
##Testing Rack Applications
|
@@ -165,10 +165,10 @@ If you're testing an API you've written in Rails, Airborne plays along with `rsp
|
|
165
165
|
require 'rails_helper'
|
166
166
|
|
167
167
|
RSpec.describe HomeController, :type => :controller do
|
168
|
-
describe
|
169
|
-
it
|
168
|
+
describe 'GET index' do
|
169
|
+
it 'returns correct types' do
|
170
170
|
get :index, :format => 'json' #if your route responds to both html and json
|
171
|
-
expect_json_types(
|
171
|
+
expect_json_types(foo: :string)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
@@ -211,9 +211,9 @@ This test would only test the address object:
|
|
211
211
|
describe 'path spec' do
|
212
212
|
it 'should allow simple path and verify only that path' do
|
213
213
|
get 'http://example.com/api/v1/simple_path_get'
|
214
|
-
expect_json_types('address',
|
214
|
+
expect_json_types('address', street: :string, city: :string, state: :string, coordinates: :object)
|
215
215
|
#or this
|
216
|
-
expect_json_types('address',
|
216
|
+
expect_json_types('address', street: :string, city: :string, state: :string, coordinates: { latitude: :float, longitude: :float })
|
217
217
|
end
|
218
218
|
end
|
219
219
|
```
|
@@ -231,7 +231,7 @@ Alternativley, if we only want to test `coordinates` we can dot into just the `c
|
|
231
231
|
```ruby
|
232
232
|
it 'should allow nested paths' do
|
233
233
|
get 'http://example.com/api/v1/simple_path_get'
|
234
|
-
expect_json('address.coordinates',
|
234
|
+
expect_json('address.coordinates', latitude: 33.3872, longitude: 104.5281)
|
235
235
|
end
|
236
236
|
```
|
237
237
|
|
@@ -259,7 +259,7 @@ We can test against just the first car like this:
|
|
259
259
|
```ruby
|
260
260
|
it 'should index into array and test against specific element' do
|
261
261
|
get '/array_api'
|
262
|
-
expect_json('cars.0',
|
262
|
+
expect_json('cars.0', make: 'Tesla', model: 'Model S')
|
263
263
|
end
|
264
264
|
```
|
265
265
|
|
@@ -268,8 +268,8 @@ To test the types of all elements in the array:
|
|
268
268
|
```ruby
|
269
269
|
it 'should test all elements of the array' do
|
270
270
|
get 'http://example.com/api/v1/array_api'
|
271
|
-
expect_json('cars.?',
|
272
|
-
expect_json_types('cars.*',
|
271
|
+
expect_json('cars.?', make: 'Tesla', model: 'Model S') # tests that one car in array matches the tesla
|
272
|
+
expect_json_types('cars.*', make: :string, model: :string) # tests all cars in array for make and model of type string
|
273
273
|
end
|
274
274
|
```
|
275
275
|
|
@@ -305,7 +305,7 @@ end
|
|
305
305
|
```ruby
|
306
306
|
it 'should check all nested arrays for specified elements' do
|
307
307
|
get 'http://example.com/api/v1/array_with_nested'
|
308
|
-
expect_json_types('cars.*.owners.*',
|
308
|
+
expect_json_types('cars.*.owners.*', name: :string)
|
309
309
|
end
|
310
310
|
```
|
311
311
|
|
@@ -315,7 +315,7 @@ JSON has no support for dates, however airborne gives you the ability to check f
|
|
315
315
|
```ruby
|
316
316
|
it 'should verify date type' do
|
317
317
|
get '/get_date' #api that returns {createdAt: "Mon Oct 20 2014 16:10:42 GMT-0400 (EDT)"}
|
318
|
-
expect_json_types(
|
318
|
+
expect_json_types(createdAt: :date)
|
319
319
|
end
|
320
320
|
```
|
321
321
|
However if you want to check the actual date data with `expect_json`, you need to call the `date` function:
|
@@ -326,7 +326,7 @@ it 'should verify correct date value' do
|
|
326
326
|
prev_day = DateTime.new(2014,10,19)
|
327
327
|
next_day = DateTime.new(2014,10,21)
|
328
328
|
#within the date callback, you can use regular RSpec expectations that work with dates
|
329
|
-
expect_json(
|
329
|
+
expect_json(createdAt: date { |value| expect(value).to be_between(prev_day, next_day) })
|
330
330
|
end
|
331
331
|
```
|
332
332
|
|
@@ -346,13 +346,13 @@ Additionally, you can specify a `base_url` and default `headers` to be used on e
|
|
346
346
|
```ruby
|
347
347
|
Airborne.configure do |config|
|
348
348
|
config.base_url = 'http://example.com/api/v1'
|
349
|
-
config.headers = {'x-auth-token' => 'my_token'}
|
349
|
+
config.headers = { 'x-auth-token' => 'my_token' }
|
350
350
|
end
|
351
351
|
|
352
352
|
describe 'spec' do
|
353
353
|
it 'now we no longer need the full url' do
|
354
354
|
get '/simple_get'
|
355
|
-
expect_json_types(
|
355
|
+
expect_json_types(name: :string)
|
356
356
|
end
|
357
357
|
end
|
358
358
|
```
|
data/airborne.gemspec
CHANGED
data/lib/airborne/base.rb
CHANGED
@@ -45,8 +45,8 @@ module Airborne
|
|
45
45
|
@response = make_request(:put, url, body: put_body, headers: headers)
|
46
46
|
end
|
47
47
|
|
48
|
-
def delete(url, headers = nil)
|
49
|
-
@response = make_request(:delete, url, headers: headers)
|
48
|
+
def delete(url, delete_body = nil, headers = nil)
|
49
|
+
@response = make_request(:delete, url, body: delete_body, headers: headers)
|
50
50
|
end
|
51
51
|
|
52
52
|
def head(url, headers = nil)
|
data/spec/stub_helper.rb
CHANGED
@@ -24,8 +24,9 @@ module StubHelper
|
|
24
24
|
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
|
25
25
|
end
|
26
26
|
|
27
|
-
def mock_delete(url)
|
28
|
-
stub_request(:delete, @base_url + url)
|
27
|
+
def mock_delete(url, options = {}, status = 200)
|
28
|
+
stub_request(:delete, @base_url + url).with(body: options[:request_body] || {})
|
29
|
+
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
|
29
30
|
end
|
30
31
|
|
31
32
|
def mock_head(url, response_headers = {}, status = 200)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airborne
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Friedman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- spec/test_responses/invalid_get.json
|
160
160
|
- spec/test_responses/invalid_json.json
|
161
161
|
- spec/test_responses/numeric_property.json
|
162
|
+
- spec/test_responses/simple_delete.json
|
162
163
|
- spec/test_responses/simple_get.json
|
163
164
|
- spec/test_responses/simple_json.json
|
164
165
|
- spec/test_responses/simple_nested_path.json
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
version: '0'
|
187
188
|
requirements: []
|
188
189
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.1.5
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
193
|
summary: RSpec driven API testing framework
|