airborne 0.1.15 → 0.1.16
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 +6 -0
- data/airborne.gemspec +4 -4
- data/lib/airborne.rb +1 -2
- data/lib/airborne/base.rb +20 -26
- data/lib/airborne/optional_hash_type_expectations.rb +3 -3
- data/lib/airborne/path_matcher.rb +10 -12
- data/lib/airborne/rack_test_requester.rb +1 -0
- data/lib/airborne/request_expectations.rb +26 -31
- data/lib/airborne/rest_client_requester.rb +16 -17
- data/spec/airborne/base_spec.rb +10 -10
- data/spec/airborne/delete_spec.rb +2 -2
- data/spec/airborne/expectations/expect_header_contains_spec.rb +6 -8
- data/spec/airborne/expectations/expect_header_spec.rb +5 -8
- data/spec/airborne/expectations/expect_json_keys_path_spec.rb +4 -6
- data/spec/airborne/expectations/expect_json_keys_spec.rb +3 -5
- data/spec/airborne/expectations/expect_json_lambda_spec.rb +2 -4
- data/spec/airborne/expectations/expect_json_path_spec.rb +72 -73
- data/spec/airborne/expectations/expect_json_regex_spec.rb +25 -27
- data/spec/airborne/expectations/expect_json_sizes_spec.rb +3 -5
- data/spec/airborne/expectations/expect_json_spec.rb +10 -6
- data/spec/airborne/expectations/expect_json_types_date_spec.rb +18 -21
- data/spec/airborne/expectations/expect_json_types_lambda_spec.rb +3 -5
- data/spec/airborne/expectations/expect_json_types_optional_spec.rb +11 -13
- data/spec/airborne/expectations/expect_json_types_path_spec.rb +52 -54
- data/spec/airborne/expectations/expect_json_types_spec.rb +18 -8
- data/spec/airborne/expectations/expect_status_spec.rb +6 -6
- data/spec/airborne/head_spec.rb +2 -2
- data/spec/airborne/options_spec.rb +2 -2
- data/spec/airborne/patch_spec.rb +2 -2
- data/spec/airborne/path_spec.rb +28 -30
- data/spec/airborne/post_spec.rb +3 -3
- data/spec/airborne/put_spec.rb +2 -2
- data/spec/airborne/rack/rack_sinatra_spec.rb +14 -7
- data/spec/spec_helper.rb +0 -1
- data/spec/stub_helper.rb +3 -4
- data/spec/test_responses/array_with_partial_nested.json +12 -0
- data/spec/test_responses/hash_property.json +3 -0
- data/spec/test_responses/simple_get.json +2 -1
- metadata +4 -2
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json_types lambda' do
|
4
|
-
|
5
|
-
it 'should invoke proc passed in' do
|
4
|
+
it 'should invoke proc passed in' do
|
6
5
|
mock_get('simple_get')
|
7
6
|
get '/simple_get'
|
8
|
-
expect_json_types(
|
7
|
+
expect_json_types(name: ->(name) { expect(name.length).to eq(4) })
|
9
8
|
end
|
10
|
-
|
11
|
-
end
|
9
|
+
end
|
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json_types optional' do
|
4
|
+
it 'should test optional nested hash when exists' do
|
5
|
+
mock_get('simple_nested_path')
|
6
|
+
get '/simple_nested_path'
|
7
|
+
expect_json_types('address.coordinates', optional(lattitude: :float, longitutde: :float))
|
8
|
+
end
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it 'should allow optional nested hash' do
|
12
|
-
mock_get('simple_path_get')
|
13
|
-
get '/simple_path_get'
|
14
|
-
expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
10
|
+
it 'should allow optional nested hash' do
|
11
|
+
mock_get('simple_path_get')
|
12
|
+
get '/simple_path_get'
|
13
|
+
expect_json_types('address.coordinates', optional(lattitude: :float, longitutde: :float))
|
14
|
+
end
|
15
|
+
end
|
@@ -1,67 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json_types wih path' do
|
4
|
+
it 'should allow simple path and verify only that path' do
|
5
|
+
mock_get('simple_path_get')
|
6
|
+
get '/simple_path_get'
|
7
|
+
expect_json_types('address', street: :string, city: :string, state: :string)
|
8
|
+
end
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
it 'should allow nested paths' do
|
11
|
+
mock_get('simple_nested_path')
|
12
|
+
get '/simple_nested_path'
|
13
|
+
expect_json_types('address.coordinates', lattitude: :float, longitutde: :float)
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
it 'should index into array and test against specific element' do
|
17
|
+
mock_get('array_with_index')
|
18
|
+
get '/array_with_index'
|
19
|
+
expect_json_types('cars.0', make: :string, model: :string)
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
it 'should allow properties to be tested against a path' do
|
23
|
+
mock_get('array_with_index')
|
24
|
+
get '/array_with_index'
|
25
|
+
expect_json_types('cars.0.make', :string)
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
it 'should test against all elements in the array' do
|
29
|
+
mock_get('array_with_index')
|
30
|
+
get '/array_with_index'
|
31
|
+
expect_json_types('cars.*', make: :string, model: :string)
|
32
|
+
end
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
it 'should ensure all elements of array are valid' do
|
35
|
+
mock_get('array_with_index')
|
36
|
+
get '/array_with_index'
|
37
|
+
expect { expect_json_types('cars.*', make: :string, model: :int) }.to raise_error
|
38
|
+
end
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
it 'should deep symbolize array responses' do
|
41
|
+
mock_get('array_response')
|
42
|
+
get '/array_response'
|
43
|
+
expect_json_types('*', name: :string)
|
44
|
+
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
it 'should check all nested arrays for specified elements' do
|
47
|
+
mock_get('array_with_nested')
|
48
|
+
get '/array_with_nested'
|
49
|
+
expect_json_types('cars.*.owners.*', name: :string)
|
50
|
+
end
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
it 'should ensure all nested arrays contain correct data' do
|
54
|
-
mock_get('array_with_nested_bad_data')
|
55
|
-
get '/array_with_nested_bad_data'
|
56
|
-
expect{expect_json_types('cars.*.owners.*', {name: :string})}.to raise_error
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should raise ExpectationError when expectation expects an object instead of type" do
|
60
|
-
mock_get('array_with_index')
|
61
|
-
get '/array_with_index'
|
62
|
-
expect do
|
63
|
-
expect_json_types('cars.0.make', {make: :string})
|
64
|
-
end.to raise_error(Airborne::ExpectationError, "Expected String Tesla\nto be an object with property make")
|
65
|
-
end
|
52
|
+
it 'should ensure all nested arrays contain correct data' do
|
53
|
+
mock_get('array_with_nested_bad_data')
|
54
|
+
get '/array_with_nested_bad_data'
|
55
|
+
expect { expect_json_types('cars.*.owners.*', name: :string) }.to raise_error
|
56
|
+
end
|
66
57
|
|
58
|
+
it 'should raise ExpectationError when expectation expects an object instead of type' do
|
59
|
+
mock_get('array_with_index')
|
60
|
+
get '/array_with_index'
|
61
|
+
expect do
|
62
|
+
expect_json_types('cars.0.make', make: :string)
|
63
|
+
end.to raise_error(Airborne::ExpectationError, "Expected String Tesla\nto be an object with property make")
|
64
|
+
end
|
67
65
|
end
|
@@ -1,47 +1,57 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_json_types' do
|
4
|
-
|
5
4
|
it 'should detect current type' do
|
6
5
|
mock_get('simple_get')
|
7
6
|
get '/simple_get'
|
8
|
-
expect_json_types(
|
7
|
+
expect_json_types(name: :string, age: :int)
|
9
8
|
end
|
10
9
|
|
11
10
|
it 'should fail when incorrect json types tested' do
|
12
11
|
mock_get('simple_get')
|
13
12
|
get '/simple_get'
|
14
|
-
expect{expect_json_types(
|
13
|
+
expect { expect_json_types(bad: :bool) }.to raise_error
|
15
14
|
end
|
16
15
|
|
17
16
|
it 'should not fail when optional property is not present' do
|
18
17
|
mock_get('simple_get')
|
19
18
|
get '/simple_get'
|
20
|
-
expect_json_types(
|
19
|
+
expect_json_types(name: :string, age: :int, optional: :bool_or_null)
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'should allow full object graph' do
|
24
23
|
mock_get('simple_path_get')
|
25
24
|
get '/simple_path_get'
|
26
|
-
expect_json_types(
|
25
|
+
expect_json_types(name: :string, address: { street: :string, city: :string, state: :string })
|
27
26
|
end
|
28
27
|
|
29
28
|
it 'should check all types in a simple array' do
|
30
29
|
mock_get('array_of_values')
|
31
30
|
get '/array_of_values'
|
32
|
-
expect_json_types(
|
31
|
+
expect_json_types(grades: :array_of_ints)
|
33
32
|
end
|
34
33
|
|
35
34
|
it 'should ensure all valid types in a simple array' do
|
36
35
|
mock_get('array_of_values')
|
37
36
|
get '/array_of_values'
|
38
|
-
expect{expect_json_types(
|
37
|
+
expect { expect_json_types(bad: :array_of_ints) }.to raise_error
|
39
38
|
end
|
40
39
|
|
41
40
|
it 'should allow empty array' do
|
42
41
|
mock_get('array_of_values')
|
43
42
|
get '/array_of_values'
|
44
|
-
expect_json_types(
|
43
|
+
expect_json_types(emptyArray: :array_of_ints)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should be able to test for a nil type' do
|
47
|
+
mock_get('simple_get')
|
48
|
+
get '/simple_get'
|
49
|
+
expect_json_types(name: :string, age: :int, address: :null)
|
45
50
|
end
|
46
51
|
|
52
|
+
it 'Should throw bad type error' do
|
53
|
+
mock_get('simple_get')
|
54
|
+
get '/simple_get'
|
55
|
+
expect { expect_json_types(name: :foo) }.to raise_error(Airborne::ExpectationError, "Expected type foo\nis an invalid type")
|
56
|
+
end
|
47
57
|
end
|
@@ -4,20 +4,20 @@ describe 'expect_status' do
|
|
4
4
|
it 'should verify correct status code' do
|
5
5
|
mock_get('simple_get')
|
6
6
|
get '/simple_get'
|
7
|
-
expect_status
|
7
|
+
expect_status 200
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should fail when incorrect status code is returned' do
|
11
11
|
mock_get('simple_get')
|
12
12
|
get '/simple_get'
|
13
|
-
expect{expect_status
|
13
|
+
expect { expect_status 123 }.to raise_error
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should translate symbol codes to whatever is appropriate for the request' do
|
17
17
|
mock_get('simple_get')
|
18
18
|
get '/simple_get'
|
19
|
-
expect_status
|
20
|
-
expect_status
|
21
|
-
expect_status
|
19
|
+
expect_status :ok
|
20
|
+
expect_status 200
|
21
|
+
expect_status '200'
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
data/spec/airborne/head_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'head' do
|
4
4
|
it 'should allow testing on head requests' do
|
5
|
-
mock_head('simple_head',
|
5
|
+
mock_head('simple_head', 'foo' => 'foo')
|
6
6
|
head '/simple_head', {}
|
7
|
-
expect_status
|
7
|
+
expect_status 200
|
8
8
|
expect_header('foo', 'foo')
|
9
9
|
end
|
10
10
|
end
|
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'head' do
|
4
4
|
it 'should allow testing on options requests' do
|
5
|
-
mock_options('simple_options',
|
5
|
+
mock_options('simple_options', 'foo' => 'foo')
|
6
6
|
options '/simple_options', {}
|
7
|
-
expect_status
|
7
|
+
expect_status 200
|
8
8
|
expect_header('foo', 'foo')
|
9
9
|
end
|
10
10
|
end
|
data/spec/airborne/patch_spec.rb
CHANGED
data/spec/airborne/path_spec.rb
CHANGED
@@ -1,36 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'expect path' do
|
3
|
+
describe 'expect path' do
|
4
|
+
describe 'errors' do
|
5
|
+
before :each do
|
6
|
+
mock_get('array_with_index')
|
7
|
+
get '/array_with_index'
|
8
|
+
end
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
it 'should raise PathError when incorrect path containing .. is used' do
|
11
|
+
expect do
|
12
|
+
expect_json('cars..make', 'Tesla')
|
13
|
+
end.to raise_error(Airborne::PathError, "Invalid Path, contains '..'")
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
it 'should raise PathError when trying to call property on an array' do
|
17
|
+
expect do
|
18
|
+
expect_json('cars.make', 'Tesla')
|
19
|
+
end.to raise_error(Airborne::PathError, "Expected Array\nto be an object with property make")
|
20
|
+
end
|
21
|
+
end
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
+
it 'should work with numberic properties' do
|
24
|
+
mock_get('numeric_property')
|
25
|
+
get '/numeric_property'
|
26
|
+
expect_json('cars.0.make', 'Tesla')
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
it "should work with numberic properties" do
|
31
|
-
mock_get('numeric_property')
|
32
|
-
get '/numeric_property'
|
33
|
-
expect_json_keys('cars.0',[:make, :model])
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
29
|
+
it 'should work with numberic properties' do
|
30
|
+
mock_get('numeric_property')
|
31
|
+
get '/numeric_property'
|
32
|
+
expect_json_keys('cars.0', [:make, :model])
|
33
|
+
end
|
34
|
+
end
|
data/spec/airborne/post_spec.rb
CHANGED
@@ -5,13 +5,13 @@ describe 'post' do
|
|
5
5
|
it 'should allow testing on post requests' do
|
6
6
|
mock_post('simple_post')
|
7
7
|
post '/simple_post', {}
|
8
|
-
expect_json_types(
|
8
|
+
expect_json_types(status: :string, someNumber: :int)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should allow testing on post requests' do
|
12
12
|
url = 'http://www.example.com/simple_post'
|
13
13
|
stub_request(:post, url)
|
14
|
-
post '/simple_post', 'hello',
|
15
|
-
expect(WebMock).to have_requested(:post, url).with(:
|
14
|
+
post '/simple_post', 'hello', content_type: 'text/plain'
|
15
|
+
expect(WebMock).to have_requested(:post, url).with(body: 'hello', headers: { 'Content-Type' => 'text/plain' })
|
16
16
|
end
|
17
17
|
end
|
data/spec/airborne/put_spec.rb
CHANGED
@@ -3,10 +3,11 @@ require 'sinatra'
|
|
3
3
|
|
4
4
|
class SampleApp < Sinatra::Application
|
5
5
|
before do
|
6
|
-
|
7
|
-
|
6
|
+
content_type 'application/json'
|
7
|
+
end
|
8
|
+
|
8
9
|
get '/' do
|
9
|
-
{foo:
|
10
|
+
{ foo: 'bar' }.to_json
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -17,11 +18,17 @@ end
|
|
17
18
|
describe 'rack app' do
|
18
19
|
it 'should allow requests against a sinatra app' do
|
19
20
|
get '/'
|
20
|
-
expect_json_types(
|
21
|
+
expect_json_types(foo: :string)
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'should ensure correct values from sinatra app' do
|
24
25
|
get '/'
|
25
|
-
expect{expect_json_types(
|
26
|
-
end
|
27
|
-
|
26
|
+
expect { expect_json_types(foo: :int) }.to raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'Should set json_body even when not using the airborne http requests' do
|
30
|
+
Response = Struct.new(:body, :headers)
|
31
|
+
@response = Response.new({ foo: 'bar' }.to_json)
|
32
|
+
expect(json_body).to eq(foo: 'bar')
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/stub_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'webmock/rspec'
|
2
2
|
|
3
3
|
module StubHelper
|
4
|
-
|
5
4
|
def initialize(*args)
|
6
5
|
@base_url = 'http://www.example.com/'
|
7
6
|
end
|
@@ -39,7 +38,7 @@ module StubHelper
|
|
39
38
|
|
40
39
|
private
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def get_json_response_file(name)
|
42
|
+
IO.read(File.join('spec/test_responses', name + '.json'))
|
43
|
+
end
|
45
44
|
end
|