airborne 0.0.21 → 0.0.22
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/Gemfile +2 -2
- data/README.md +5 -15
- data/airborne.gemspec +1 -1
- data/lib/airborne.rb +6 -6
- data/lib/airborne/base.rb +74 -84
- data/lib/airborne/optional_hash_type_expectations.rb +12 -12
- data/lib/airborne/path_matcher.rb +43 -43
- data/lib/airborne/rack_test_requester.rb +7 -7
- data/lib/airborne/request_expectations.rb +118 -112
- data/lib/airborne/rest_client_requester.rb +21 -21
- data/spec/airborne/base_spec.rb +50 -50
- data/spec/airborne/delete_spec.rb +5 -5
- data/spec/airborne/expect_json_keys_spec.rb +27 -15
- data/spec/airborne/expect_json_spec.rb +54 -54
- data/spec/airborne/expect_json_types_spec.rb +107 -107
- data/spec/airborne/expect_status_spec.rb +10 -10
- data/spec/airborne/headers_spec.rb +25 -25
- data/spec/airborne/patch_spec.rb +5 -5
- data/spec/airborne/post_spec.rb +5 -5
- data/spec/airborne/put_spec.rb +5 -5
- data/spec/airborne/rack_sinatra_spec.rb +15 -15
- data/spec/spec_helper.rb +2 -2
- data/spec/stub_helper.rb +32 -32
- metadata +2 -2
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
|
3
3
|
module Airborne
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
module RestClientRequester
|
5
|
+
def make_request(method, url, options = {})
|
6
|
+
headers = (options[:headers] || {}).merge({content_type: :json})
|
7
|
+
base_headers = Airborne.configuration.headers || {}
|
8
|
+
headers = base_headers.merge(headers)
|
9
|
+
res = if method == :post || method == :patch || method == :put
|
10
|
+
begin
|
11
|
+
RestClient.send(method, get_url(url), options[:body].nil? ? "" : options[:body].to_json, headers)
|
12
|
+
rescue RestClient::Exception => e
|
13
|
+
e.response
|
14
|
+
end
|
15
|
+
else
|
16
|
+
begin
|
17
|
+
RestClient.send(method, get_url(url), headers)
|
18
|
+
rescue RestClient::Exception => e
|
19
|
+
e.response
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
end
|
23
|
+
res
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
data/spec/airborne/base_spec.rb
CHANGED
@@ -1,54 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'base spec' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
4
|
+
it 'when request is made response should be set' do
|
5
|
+
mock_get('simple_get')
|
6
|
+
get '/simple_get'
|
7
|
+
expect(response).to_not be(nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'when request is made headers should be set' do
|
11
|
+
mock_get('simple_get')
|
12
|
+
get '/simple_get'
|
13
|
+
expect(headers).to_not be(nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'when request is made headers should be hash with indifferent access' do
|
17
|
+
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
18
|
+
get '/simple_get'
|
19
|
+
expect(headers).to be_kind_of(Hash)
|
20
|
+
expect(headers[:content_type]).to eq('application/json')
|
21
|
+
expect(headers['content_type']).to eq('application/json')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'when request is made body should be set' do
|
25
|
+
mock_get('simple_get')
|
26
|
+
get '/simple_get'
|
27
|
+
expect(body).to_not be(nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'when request is made json body should be symbolized hash' do
|
31
|
+
mock_get('simple_get')
|
32
|
+
get '/simple_get'
|
33
|
+
expect(json_body).to be_kind_of(Hash)
|
34
|
+
expect(json_body.first[0]).to be_kind_of(Symbol)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not error on invalid JSON' do
|
38
|
+
mock_get('invalid_get')
|
39
|
+
get '/invalid_get'
|
40
|
+
expect(json_body).to be(nil)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should handle a 500 error on get' do
|
44
|
+
mock_get('simple_get', {}, [500, "Internal Server Error"])
|
45
|
+
get '/simple_get'
|
46
|
+
expect(json_body).to_not be(nil)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should handle a 500 error on post' do
|
50
|
+
mock_post('simple_post', {}, [500, "Internal Server Error"])
|
51
|
+
post '/simple_post', {}
|
52
|
+
expect(json_body).to_not be(nil)
|
53
|
+
end
|
54
54
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'delete' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should allow testing on delete requests' do
|
5
|
+
mock_delete 'simple_delete'
|
6
|
+
delete '/simple_delete'
|
7
|
+
expect_status(200)
|
8
|
+
end
|
9
9
|
end
|
@@ -1,21 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json_keys' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should fail when json keys are missing' do
|
5
|
+
mock_get('simple_json')
|
6
|
+
get '/simple_json', {}
|
7
|
+
expect{expect_json_keys([:foo, :bar, :baz, :bax])}.to raise_error
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it 'should ensure correct json keys' do
|
11
|
+
mock_get('simple_json')
|
12
|
+
get '/simple_json', {}
|
13
|
+
expect_json_keys([:foo, :bar, :baz])
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
it 'should ensure correct partial json keys' do
|
17
|
+
mock_get('simple_json')
|
18
|
+
get '/simple_json', {}
|
19
|
+
expect_json_keys([:foo, :bar])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should ensure json keys with path' do
|
23
|
+
mock_get('simple_nested_path')
|
24
|
+
get '/simple_nested_path', {}
|
25
|
+
expect_json_keys('address', [:street, :city])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should fail when keys are missing with path' do
|
29
|
+
mock_get('simple_nested_path')
|
30
|
+
get '/simple_nested_path', {}
|
31
|
+
expect{expect_json_keys('address', [:bad])}.to raise_error
|
32
|
+
end
|
21
33
|
end
|
@@ -1,65 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should ensure correct json values' do
|
5
|
+
mock_get('simple_get')
|
6
|
+
get '/simple_get'
|
7
|
+
expect_json({name: "Alex", age: 32 })
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
10
|
+
it 'should fail when incorrect json is tested' do
|
11
|
+
mock_get('simple_get')
|
12
|
+
get '/simple_get'
|
13
|
+
expect{expect_json({bad: "data"})}.to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should allow simple path and verify only that path' do
|
17
|
+
mock_get('simple_path_get')
|
18
|
+
get '/simple_path_get'
|
19
|
+
expect_json('address', {street: "Area 51", city: "Roswell", state: "NM"})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should allow full object graph' do
|
23
|
+
mock_get('simple_path_get')
|
24
|
+
get '/simple_path_get'
|
25
|
+
expect_json({name: "Alex", address: {street: "Area 51", city: "Roswell", state: "NM"}})
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
it 'should allow nested paths' do
|
29
|
+
mock_get('simple_nested_path')
|
30
|
+
get '/simple_nested_path'
|
31
|
+
expect_json('address.coordinates', {lattitude: 33.3872, longitutde: 104.5281} )
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
34
|
+
it 'should index into array and test against specific element' do
|
35
|
+
mock_get('array_with_index')
|
36
|
+
get '/array_with_index'
|
37
|
+
expect_json('cars.0', {make: "Tesla", model: "Model S"})
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should test against all elements in the array' do
|
41
|
+
mock_get('array_with_index')
|
42
|
+
get '/array_with_index'
|
43
|
+
expect_json('cars.?', {make: "Tesla", model: "Model S"})
|
44
|
+
expect_json('cars.?', {make: "Lamborghini", model: "Aventador"})
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
it 'should invoke proc passed in' do
|
48
|
+
mock_get('simple_get')
|
49
|
+
get '/simple_get'
|
50
|
+
expect_json({name: -> (name){expect(name.length).to eq(4)}})
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
it 'should test against regex' do
|
54
|
+
mock_get('simple_get')
|
55
|
+
get '/simple_get'
|
56
|
+
expect_json({name: regex("^A")})
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
it 'should raise an error if regex does not match' do
|
60
|
+
mock_get('simple_get')
|
61
|
+
get '/simple_get'
|
62
|
+
expect{expect_json({name: regex("^B")})}.to raise_error
|
63
|
+
end
|
64
64
|
|
65
65
|
end
|
@@ -1,111 +1,111 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json_types' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
4
|
+
it 'should detect current type' do
|
5
|
+
mock_get('simple_get')
|
6
|
+
get '/simple_get'
|
7
|
+
expect_json_types({name: :string, age: :int})
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should fail when incorrect json types tested' do
|
11
|
+
mock_get('simple_get')
|
12
|
+
get '/simple_get'
|
13
|
+
expect{expect_json_types({bad: :bool})}.to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not fail when optional property is not present' do
|
17
|
+
mock_get('simple_get')
|
18
|
+
get '/simple_get'
|
19
|
+
expect_json_types({name: :string, age: :int, optional: :bool_or_null })
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should allow simple path and verify only that path' do
|
23
|
+
mock_get('simple_path_get')
|
24
|
+
get '/simple_path_get'
|
25
|
+
expect_json_types('address', {street: :string, city: :string, state: :string})
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should allow full object graph' do
|
29
|
+
mock_get('simple_path_get')
|
30
|
+
get '/simple_path_get'
|
31
|
+
expect_json_types({name: :string, address: {street: :string, city: :string, state: :string}})
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should allow nested paths' do
|
35
|
+
mock_get('simple_nested_path')
|
36
|
+
get '/simple_nested_path'
|
37
|
+
expect_json_types('address.coordinates', {lattitude: :float, longitutde: :float} )
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should index into array and test against specific element' do
|
41
|
+
mock_get('array_with_index')
|
42
|
+
get '/array_with_index'
|
43
|
+
expect_json_types('cars.0', {make: :string, model: :string})
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should test against all elements in the array' do
|
47
|
+
mock_get('array_with_index')
|
48
|
+
get '/array_with_index'
|
49
|
+
expect_json_types('cars.*', {make: :string, model: :string})
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should ensure all elements of array are valid' do
|
53
|
+
mock_get('array_with_index')
|
54
|
+
get '/array_with_index'
|
55
|
+
expect{expect_json_types('cars.*', {make: :string, model: :int})}.to raise_error
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should check all nested arrays for specified elements' do
|
59
|
+
mock_get('array_with_nested')
|
60
|
+
get '/array_with_nested'
|
61
|
+
expect_json_types('cars.*.owners.*', {name: :string})
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should ensure all nested arrays contain correct data' do
|
65
|
+
mock_get('array_with_nested_bad_data')
|
66
|
+
get '/array_with_nested_bad_data'
|
67
|
+
expect{expect_json_types('cars.*.owners.*', {name: :string})}.to raise_error
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should check all types in a simple array' do
|
71
|
+
mock_get('array_of_values')
|
72
|
+
get '/array_of_values'
|
73
|
+
expect_json_types({grades: :array_of_ints})
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should ensure all valid types in a simple array' do
|
77
|
+
mock_get('array_of_values')
|
78
|
+
get '/array_of_values'
|
79
|
+
expect{expect_json_types({bad: :array_of_ints})}.to raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should deep symbolize array responses' do
|
83
|
+
mock_get('array_response')
|
84
|
+
get '/array_response'
|
85
|
+
expect_json_types("*", {name: :string})
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should allow empty array' do
|
89
|
+
mock_get('array_of_values')
|
90
|
+
get '/array_of_values'
|
91
|
+
expect_json_types({emptyArray: :array_of_ints})
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should test optional nested hash when exists' do
|
95
|
+
mock_get('simple_nested_path')
|
96
|
+
get '/simple_nested_path'
|
97
|
+
expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should allow optional nested hash' do
|
101
|
+
mock_get('simple_path_get')
|
102
|
+
get '/simple_path_get'
|
103
|
+
expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should invoke proc passed in' do
|
107
|
+
mock_get('simple_get')
|
108
|
+
get '/simple_get'
|
109
|
+
expect_json_types({name: -> (name){expect(name.length).to eq(4)}})
|
110
|
+
end
|
111
111
|
end
|