airborne 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -0
  3. data/airborne.gemspec +4 -4
  4. data/lib/airborne.rb +1 -2
  5. data/lib/airborne/base.rb +20 -26
  6. data/lib/airborne/optional_hash_type_expectations.rb +3 -3
  7. data/lib/airborne/path_matcher.rb +10 -12
  8. data/lib/airborne/rack_test_requester.rb +1 -0
  9. data/lib/airborne/request_expectations.rb +26 -31
  10. data/lib/airborne/rest_client_requester.rb +16 -17
  11. data/spec/airborne/base_spec.rb +10 -10
  12. data/spec/airborne/delete_spec.rb +2 -2
  13. data/spec/airborne/expectations/expect_header_contains_spec.rb +6 -8
  14. data/spec/airborne/expectations/expect_header_spec.rb +5 -8
  15. data/spec/airborne/expectations/expect_json_keys_path_spec.rb +4 -6
  16. data/spec/airborne/expectations/expect_json_keys_spec.rb +3 -5
  17. data/spec/airborne/expectations/expect_json_lambda_spec.rb +2 -4
  18. data/spec/airborne/expectations/expect_json_path_spec.rb +72 -73
  19. data/spec/airborne/expectations/expect_json_regex_spec.rb +25 -27
  20. data/spec/airborne/expectations/expect_json_sizes_spec.rb +3 -5
  21. data/spec/airborne/expectations/expect_json_spec.rb +10 -6
  22. data/spec/airborne/expectations/expect_json_types_date_spec.rb +18 -21
  23. data/spec/airborne/expectations/expect_json_types_lambda_spec.rb +3 -5
  24. data/spec/airborne/expectations/expect_json_types_optional_spec.rb +11 -13
  25. data/spec/airborne/expectations/expect_json_types_path_spec.rb +52 -54
  26. data/spec/airborne/expectations/expect_json_types_spec.rb +18 -8
  27. data/spec/airborne/expectations/expect_status_spec.rb +6 -6
  28. data/spec/airborne/head_spec.rb +2 -2
  29. data/spec/airborne/options_spec.rb +2 -2
  30. data/spec/airborne/patch_spec.rb +2 -2
  31. data/spec/airborne/path_spec.rb +28 -30
  32. data/spec/airborne/post_spec.rb +3 -3
  33. data/spec/airborne/put_spec.rb +2 -2
  34. data/spec/airborne/rack/rack_sinatra_spec.rb +14 -7
  35. data/spec/spec_helper.rb +0 -1
  36. data/spec/stub_helper.rb +3 -4
  37. data/spec/test_responses/array_with_partial_nested.json +12 -0
  38. data/spec/test_responses/hash_property.json +3 -0
  39. data/spec/test_responses/simple_get.json +2 -1
  40. metadata +4 -2
@@ -4,6 +4,6 @@ describe 'delete' do
4
4
  it 'should allow testing on delete requests' do
5
5
  mock_delete 'simple_delete'
6
6
  delete '/simple_delete'
7
- expect_status(200)
7
+ expect_status 200
8
8
  end
9
- end
9
+ end
@@ -1,23 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect header contains' do
4
-
5
4
  it 'should ensure partial header match exists' do
6
- mock_get('simple_get', {'Content-Type' => 'application/json'})
5
+ mock_get('simple_get', 'Content-Type' => 'application/json')
7
6
  get '/simple_get'
8
7
  expect_header_contains(:content_type, 'json')
9
8
  end
10
9
 
11
10
  it 'should ensure header is present' do
12
- mock_get('simple_get', {'Content-Type' => 'application/json'})
11
+ mock_get('simple_get', 'Content-Type' => 'application/json')
13
12
  get '/simple_get'
14
- expect{expect_header_contains(:foo, 'bar')}.to raise_error
13
+ expect { expect_header_contains(:foo, 'bar') }.to raise_error
15
14
  end
16
15
 
17
16
  it 'should ensure partial header is present' do
18
- mock_get('simple_get', {'Content-Type' => 'application/json'})
17
+ mock_get('simple_get', 'Content-Type' => 'application/json')
19
18
  get '/simple_get'
20
- expect{expect_header_contains(:content_type, 'bar')}.to raise_error
19
+ expect { expect_header_contains(:content_type, 'bar') }.to raise_error
21
20
  end
22
-
23
- end
21
+ end
@@ -1,24 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect header' do
4
-
5
4
  it 'should find exact match for header content' do
6
- mock_get('simple_get', {'Content-Type' => 'application/json'})
5
+ mock_get('simple_get', 'Content-Type' => 'application/json')
7
6
  get '/simple_get'
8
7
  expect_header(:content_type, 'application/json')
9
8
  end
10
9
 
11
10
  it 'should find exact match for header content' do
12
- mock_get('simple_get', {'Content-Type' => 'json'})
11
+ mock_get('simple_get', 'Content-Type' => 'json')
13
12
  get '/simple_get'
14
- expect{expect_header(:content_type, 'application/json')}.to raise_error
13
+ expect { expect_header(:content_type, 'application/json') }.to raise_error
15
14
  end
16
15
 
17
16
  it 'should ensure correct headers are present' do
18
- mock_get('simple_get', {'Content-Type' => 'application/json'})
17
+ mock_get('simple_get', 'Content-Type' => 'application/json')
19
18
  get '/simple_get'
20
- expect{expect_header(:foo, 'bar')}.to raise_error
19
+ expect { expect_header(:foo, 'bar') }.to raise_error
21
20
  end
22
-
23
21
  end
24
-
@@ -1,17 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json_keys with path' do
4
-
5
4
  it 'should ensure json keys with path' do
6
5
  mock_get('simple_nested_path')
7
6
  get '/simple_nested_path', {}
8
7
  expect_json_keys('address', [:street, :city])
9
- end
8
+ end
10
9
 
11
10
  it 'should fail when keys are missing with path' do
12
11
  mock_get('simple_nested_path')
13
12
  get '/simple_nested_path', {}
14
- expect{expect_json_keys('address', [:bad])}.to raise_error
15
- end
16
-
17
- end
13
+ expect { expect_json_keys('address', [:bad]) }.to raise_error
14
+ end
15
+ end
@@ -1,23 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json_keys' do
4
-
5
4
  it 'should fail when json keys are missing' do
6
5
  mock_get('simple_json')
7
6
  get '/simple_json', {}
8
- expect{expect_json_keys([:foo, :bar, :baz, :bax])}.to raise_error
7
+ expect { expect_json_keys([:foo, :bar, :baz, :bax]) }.to raise_error
9
8
  end
10
9
 
11
10
  it 'should ensure correct json keys' do
12
11
  mock_get('simple_json')
13
12
  get '/simple_json', {}
14
13
  expect_json_keys([:foo, :bar, :baz])
15
- end
14
+ end
16
15
 
17
16
  it 'should ensure correct partial json keys' do
18
17
  mock_get('simple_json')
19
18
  get '/simple_json', {}
20
19
  expect_json_keys([:foo, :bar])
21
20
  end
22
-
23
- end
21
+ end
@@ -1,11 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json lambda' do
4
-
5
4
  it 'should invoke proc passed in' do
6
5
  mock_get('simple_get')
7
6
  get '/simple_get'
8
- expect_json({name: ->(name){expect(name.length).to eq(4)}})
7
+ expect_json(name: ->(name) { expect(name.length).to eq(4) })
9
8
  end
10
-
11
- end
9
+ end
@@ -1,109 +1,108 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json with 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('address', street: 'Area 51', city: 'Roswell', state: 'NM')
8
+ end
9
+
10
+ it 'should allow nested paths' do
11
+ mock_get('simple_nested_path')
12
+ get '/simple_nested_path'
13
+ expect_json('address.coordinates', lattitude: 33.3872, longitutde: 104.5281)
14
+ end
4
15
 
5
- it 'should allow simple path and verify only that path' do
6
- mock_get('simple_path_get')
7
- get '/simple_path_get'
8
- expect_json('address', {street: "Area 51", city: "Roswell", state: "NM"})
9
- end
10
-
11
- it 'should allow nested paths' do
12
- mock_get('simple_nested_path')
13
- get '/simple_nested_path'
14
- expect_json('address.coordinates', {lattitude: 33.3872, longitutde: 104.5281} )
15
- end
16
-
17
- it 'should index into array and test against specific element' do
18
- mock_get('array_with_index')
19
- get '/array_with_index'
20
- expect_json('cars.0', {make: "Tesla", model: "Model S"})
21
- end
22
-
23
- it 'should test against all elements in the array' do
24
- mock_get('array_with_index')
25
- get '/array_with_index'
26
- expect_json('cars.?', {make: "Tesla", model: "Model S"})
27
- expect_json('cars.?', {make: "Lamborghini", model: "Aventador"})
28
- end
29
-
30
- it 'should test against properties in the array' do
31
- mock_get('array_with_index')
32
- get '/array_with_index'
33
- expect_json('cars.?.make', "Tesla")
34
- end
35
-
36
- it 'should ensure at least one match' do
37
- mock_get('array_with_index')
38
- get '/array_with_index'
39
- expect{expect_json('cars.?.make', "Teslas")}.to raise_error
40
- end
41
-
42
- it 'should check for at least one match' do
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('cars.0', make: 'Tesla', model: 'Model S')
20
+ end
21
+
22
+ it 'should test against all elements in the array' do
23
+ mock_get('array_with_index')
24
+ get '/array_with_index'
25
+ expect_json('cars.?', make: 'Tesla', model: 'Model S')
26
+ expect_json('cars.?', make: 'Lamborghini', model: 'Aventador')
27
+ end
28
+
29
+ it 'should test against properties in the array' do
30
+ mock_get('array_with_index')
31
+ get '/array_with_index'
32
+ expect_json('cars.?.make', 'Tesla')
33
+ end
34
+
35
+ it 'should ensure at least one match' do
36
+ mock_get('array_with_index')
37
+ get '/array_with_index'
38
+ expect { expect_json('cars.?.make', 'Teslas') }.to raise_error
39
+ end
40
+
41
+ it 'should check for at least one match' do
43
42
  mock_get('array_with_nested')
44
43
  get '/array_with_nested'
45
- expect_json('cars.?.owners.?', {name: "Bart Simpson"})
44
+ expect_json('cars.?.owners.?', name: 'Bart Simpson')
46
45
  end
47
46
 
48
47
  it 'should ensure at least one match' do
49
48
  mock_get('array_with_nested')
50
49
  get '/array_with_nested'
51
- expect{expect_json('cars.?.owners.?', {name: "Bart Simpsons"})}.to raise_error
50
+ expect { expect_json('cars.?.owners.?', name: 'Bart Simpsons') }.to raise_error
52
51
  end
53
52
 
54
53
  it 'should check for one match that matches all ' do
55
54
  mock_get('array_with_nested')
56
55
  get '/array_with_nested'
57
- expect_json('cars.?.owners.*', {name: "Bart Simpson"})
56
+ expect_json('cars.?.owners.*', name: 'Bart Simpson')
58
57
  end
59
58
 
60
59
  it 'should check for one match that matches all with lambda' do
61
60
  mock_get('array_with_nested')
62
61
  get '/array_with_nested'
63
- expect_json('cars.?.owners.*', {name: ->(name){expect(name).to eq("Bart Simpson")}})
62
+ expect_json('cars.?.owners.*', name: ->(name) { expect(name).to eq('Bart Simpson') })
64
63
  end
65
64
 
66
65
  it 'should ensure one match that matches all with lambda' do
67
66
  mock_get('array_with_nested')
68
67
  get '/array_with_nested'
69
- expect{expect_json('cars.?.owners.*', {name: ->(name){expect(name).to eq("Bart Simpsons")}})}.to raise_error
68
+ expect { expect_json('cars.?.owners.*', name: ->(name) { expect(name).to eq('Bart Simpsons') }) }.to raise_error
70
69
  end
71
70
 
72
71
  it 'should ensure one match that matches all' do
73
72
  mock_get('array_with_nested')
74
73
  get '/array_with_nested'
75
- expect{expect_json('cars.?.owners.*', {name: "Bart Simpsons"})}.to raise_error
74
+ expect { expect_json('cars.?.owners.*', name: 'Bart Simpsons') }.to raise_error
76
75
  end
77
76
 
78
- it 'should allow indexing' do
77
+ it 'should allow indexing' do
79
78
  mock_get('array_with_nested')
80
79
  get '/array_with_nested'
81
- expect_json('cars.0.owners.0', {name: "Bart Simpson"})
82
- end
83
-
84
- it 'should allow strings (String) to be tested against a path' do
85
- mock_get('simple_nested_path')
86
- get '/simple_nested_path'
87
- expect_json('address.city', "Roswell" )
88
- end
89
-
90
- it 'should allow floats (Float) to be tested against a path' do
91
- mock_get('simple_nested_path')
92
- get '/simple_nested_path'
93
- expect_json('address.coordinates.lattitude', 33.3872 )
94
- end
95
-
96
- it 'should allow integers (Fixnum, Bignum) to be tested against a path' do
97
- mock_get('simple_get')
98
- get '/simple_get'
99
- expect_json('age', 32 )
100
- end
101
-
102
- it "should raise ExpectationError when expectation expects an object instead of value" do
103
- mock_get('array_with_index')
104
- get '/array_with_index'
105
- expect do
106
- expect_json('cars.0.make', {make: "Tesla"})
107
- end.to raise_error(Airborne::ExpectationError, "Expected String Tesla\nto be an object with property make")
108
- end
80
+ expect_json('cars.0.owners.0', name: 'Bart Simpson')
81
+ end
82
+
83
+ it 'should allow strings (String) to be tested against a path' do
84
+ mock_get('simple_nested_path')
85
+ get '/simple_nested_path'
86
+ expect_json('address.city', 'Roswell')
87
+ end
88
+
89
+ it 'should allow floats (Float) to be tested against a path' do
90
+ mock_get('simple_nested_path')
91
+ get '/simple_nested_path'
92
+ expect_json('address.coordinates.lattitude', 33.3872)
93
+ end
94
+
95
+ it 'should allow integers (Fixnum, Bignum) to be tested against a path' do
96
+ mock_get('simple_get')
97
+ get '/simple_get'
98
+ expect_json('age', 32)
99
+ end
100
+
101
+ it 'should raise ExpectationError when expectation expects an object instead of value' do
102
+ mock_get('array_with_index')
103
+ get '/array_with_index'
104
+ expect do
105
+ expect_json('cars.0.make', make: 'Tesla')
106
+ end.to raise_error(Airborne::ExpectationError, "Expected String Tesla\nto be an object with property make")
107
+ end
109
108
  end
@@ -1,35 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json regex' do
4
+ it 'should test against regex' do
5
+ mock_get('simple_get')
6
+ get '/simple_get'
7
+ expect_json(name: regex('^A'))
8
+ end
4
9
 
5
- it 'should test against regex' do
6
- mock_get('simple_get')
7
- get '/simple_get'
8
- expect_json({name: regex("^A")})
9
- end
10
+ it 'should raise an error if regex does not match' do
11
+ mock_get('simple_get')
12
+ get '/simple_get'
13
+ expect { expect_json(name: regex('^B')) }.to raise_error
14
+ end
10
15
 
11
- it 'should raise an error if regex does not match' do
12
- mock_get('simple_get')
13
- get '/simple_get'
14
- expect{expect_json({name: regex("^B")})}.to raise_error
15
- end
16
+ it 'should allow regex(Regexp) to be tested against a path' do
17
+ mock_get('simple_nested_path')
18
+ get '/simple_nested_path'
19
+ expect_json('address.city', regex('^R'))
20
+ end
16
21
 
17
- it 'should allow regex(Regexp) to be tested against a path' do
18
- mock_get('simple_nested_path')
19
- get '/simple_nested_path'
20
- expect_json('address.city', regex("^R") )
21
- end
22
+ it 'should allow testing regex against numbers directly' do
23
+ mock_get('simple_nested_path')
24
+ get '/simple_nested_path'
25
+ expect_json('address.coordinates.lattitude', regex('^3'))
26
+ end
22
27
 
23
- it 'should allow testing regex against numbers directly' do
24
- mock_get('simple_nested_path')
25
- get '/simple_nested_path'
26
- expect_json('address.coordinates.lattitude', regex("^3") )
27
- end
28
-
29
- it 'should allow testing regex against numbers in the hash' do
30
- mock_get('simple_nested_path')
31
- get '/simple_nested_path'
32
- expect_json('address.coordinates', {lattitude: regex("^3")} )
33
- end
34
-
28
+ it 'should allow testing regex against numbers in the hash' do
29
+ mock_get('simple_nested_path')
30
+ get '/simple_nested_path'
31
+ expect_json('address.coordinates', lattitude: regex('^3'))
32
+ end
35
33
  end
@@ -1,17 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json_sizes' do
4
-
5
4
  it 'should detect sizes' do
6
5
  mock_get('array_of_values')
7
6
  get '/array_of_values'
8
- expect_json_sizes({grades: 4, bad: 3, emptyArray: 0})
7
+ expect_json_sizes(grades: 4, bad: 3, emptyArray: 0)
9
8
  end
10
9
 
11
10
  it 'should allow full object graph' do
12
11
  mock_get('array_with_nested')
13
12
  get '/array_with_nested'
14
- expect_json_sizes({cars: {0 => {owners: 1}, 1 => {owners: 1}}})
13
+ expect_json_sizes(cars: { 0 => { owners: 1 }, 1 => { owners: 1 } })
15
14
  end
16
15
 
17
16
  it 'should allow properties to be tested against a path' do
@@ -29,7 +28,6 @@ describe 'expect_json_sizes' do
29
28
  it 'should test against all elements in the array when path contains * AND expectation is a Hash' do
30
29
  mock_get('array_with_nested')
31
30
  get '/array_with_nested'
32
- expect_json_sizes('cars.*', {owners: 1})
31
+ expect_json_sizes('cars.*', owners: 1)
33
32
  end
34
-
35
33
  end
@@ -1,23 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json' do
4
-
5
4
  it 'should ensure correct json values' do
6
5
  mock_get('simple_get')
7
6
  get '/simple_get'
8
- expect_json({name: "Alex", age: 32 })
7
+ expect_json(name: 'Alex', age: 32)
9
8
  end
10
9
 
11
10
  it 'should fail when incorrect json is tested' do
12
11
  mock_get('simple_get')
13
12
  get '/simple_get'
14
- expect{expect_json({bad: "data"})}.to raise_error
13
+ expect { expect_json(bad: 'data') }.to raise_error
15
14
  end
16
-
15
+
17
16
  it 'should allow full object graph' do
18
17
  mock_get('simple_path_get')
19
18
  get '/simple_path_get'
20
- expect_json({name: "Alex", address: {street: "Area 51", city: "Roswell", state: "NM"}})
19
+ expect_json(name: 'Alex', address: { street: 'Area 51', city: 'Roswell', state: 'NM' })
21
20
  end
22
21
 
23
- end
22
+ it 'should ensure keys in hashes do match' do
23
+ mock_get('hash_property')
24
+ get '/hash_property'
25
+ expect { expect_json(person: { name: 'Alex', something: nil }) }.to raise_error
26
+ end
27
+ end
@@ -2,28 +2,25 @@ require 'spec_helper'
2
2
  require 'date'
3
3
 
4
4
  describe 'expect_json_types with date' do
5
- it 'should verify correct date types' do
6
- mock_get('date_response')
7
- get '/date_response'
5
+ it 'should verify correct date types' do
6
+ mock_get('date_response')
7
+ get '/date_response'
8
+ expect_json_types(createdAt: :date)
9
+ end
8
10
 
9
- expect_json_types({createdAt: :date})
10
- end
11
-
12
- it 'should verify correct date types with path' do
13
- mock_get('date_response')
14
- get '/date_response'
15
-
16
- expect_json_types("createdAt", :date)
17
- end
11
+ it 'should verify correct date types with path' do
12
+ mock_get('date_response')
13
+ get '/date_response'
14
+ expect_json_types('createdAt', :date)
15
+ end
18
16
  end
19
17
 
20
18
  describe 'expect_json with date' do
21
- it 'should verify correct date value' do
22
- mock_get('date_response')
23
- get '/date_response'
24
-
25
- prev_day = DateTime.new(2014,10,19)
26
- next_day = DateTime.new(2014,10,21)
27
- expect_json({createdAt: date {|value| expect(value).to be_between(prev_day, next_day)}})
28
- end
29
- end
19
+ it 'should verify correct date value' do
20
+ mock_get('date_response')
21
+ get '/date_response'
22
+ prev_day = DateTime.new(2014, 10, 19)
23
+ next_day = DateTime.new(2014, 10, 21)
24
+ expect_json(createdAt: date { |value| expect(value).to be_between(prev_day, next_day) })
25
+ end
26
+ end