airborne 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +13 -1
- data/airborne.gemspec +2 -2
- data/lib/airborne/rack_test_requester.rb +4 -1
- data/lib/airborne/request_expectations.rb +42 -5
- data/spec/airborne/expectations/expect_json_sizes_spec.rb +35 -0
- data/spec/airborne/expectations/{expect_json_types_date.rb → expect_json_types_date_spec.rb} +0 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e351c7ecb46e7a53eb2f615feefe937d25378f7
|
4
|
+
data.tar.gz: 64dbeff0d1bf50ae25d1827bfacf07e25431db98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b26d99981f1864fd92be88b377fc442321f5f7aa258fc440d5440814570a592cdc792fe3d1d2d7c8e3a7add80efa593f5c55049efebfacec397fe54c6eeb7dcf
|
7
|
+
data.tar.gz: fcfbff4c0167958d07d757557c64eade67bbfda6f183eee3238aded65f4618c253059e8f05af24fe11aab32d4723a859f63b1e85f99a0a4f778aa155b1ab3ea0
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -95,6 +95,17 @@ describe 'sample spec' do
|
|
95
95
|
end
|
96
96
|
```
|
97
97
|
|
98
|
+
Calling `expect_json_sizes` actually make use of the above feature and call `expect_json` under the hood:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
describe 'sample spec' do
|
102
|
+
it 'should validate types' do
|
103
|
+
get 'http://example.com/api/v1/simple_get_collection' #json api that returns { "ids" : [1, 2, 3, 4] }
|
104
|
+
expect_json_sizes({ids: 4})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
98
109
|
##Making requests
|
99
110
|
|
100
111
|
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`. This will then give you access the following properties:
|
@@ -161,13 +172,14 @@ end
|
|
161
172
|
* `expect_json_types` - Tests the types of the JSON property values returned
|
162
173
|
* `expect_json` - Tests the values of the JSON property values returned
|
163
174
|
* `expect_json_keys` - Tests the existence of the specified keys in the JSON object
|
175
|
+
* `expect_json_sizes` - Tests the sizes of the JSON property values returned, also test if the values are arrays
|
164
176
|
* `expect_status` - Tests the HTTP status code returned
|
165
177
|
* `expect_header` - Tests for a specified header in the response
|
166
178
|
* `expect_header_contains` - Partial match test on a specified header
|
167
179
|
|
168
180
|
##Path Matching
|
169
181
|
|
170
|
-
When calling `expect_json_types`, `expect_json` or `
|
182
|
+
When calling `expect_json_types`, `expect_json`, `expect_json_keys` or `expect_json_sizes` you can optionally specify a path as a first parameter.
|
171
183
|
|
172
184
|
For example, if our API returns the following JSON:
|
173
185
|
|
data/airborne.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'airborne'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2014-
|
3
|
+
s.version = '0.1.2'
|
4
|
+
s.date = '2014-11-15'
|
5
5
|
s.summary = "RSpec driven API testing framework"
|
6
6
|
s.authors = ["Alex Friedman", "Seth Pollack"]
|
7
7
|
s.email = ['a.friedman07@gmail.com', 'teampollack@gmail.com']
|
@@ -5,7 +5,10 @@ module Airborne
|
|
5
5
|
def make_request(method, url, options = {})
|
6
6
|
browser = Rack::Test::Session.new(Rack::MockSession.new(Airborne.configuration.rack_app))
|
7
7
|
browser.send(method, url, options[:body] || {}, options[:headers] || {})
|
8
|
+
Rack::MockResponse.class_eval do
|
9
|
+
alias_method :code, :status
|
10
|
+
end
|
8
11
|
browser.last_response
|
9
12
|
end
|
10
13
|
end
|
11
|
-
end
|
14
|
+
end
|
@@ -24,6 +24,12 @@ module Airborne
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def expect_json_sizes(*args)
|
28
|
+
args.push(convert_expectations_for_json_sizes(args.pop))
|
29
|
+
|
30
|
+
expect_json_types(*args)
|
31
|
+
end
|
32
|
+
|
27
33
|
def expect_status(code)
|
28
34
|
expect(response.code).to eq(code)
|
29
35
|
end
|
@@ -113,17 +119,24 @@ module Airborne
|
|
113
119
|
mapper
|
114
120
|
end
|
115
121
|
|
116
|
-
def expect_json_types_impl(expectations,
|
117
|
-
return if is_nil_optional_hash?(expectations,
|
122
|
+
def expect_json_types_impl(expectations, hash_or_value)
|
123
|
+
return if is_nil_optional_hash?(expectations, hash_or_value)
|
124
|
+
|
118
125
|
@mapper ||= get_mapper
|
119
|
-
|
120
|
-
|
126
|
+
|
127
|
+
hash_or_value = convert_to_date(hash_or_value) if expectations == :date
|
128
|
+
|
129
|
+
return expect_type(expectations, hash_or_value.class) if expectations.class == Symbol
|
130
|
+
return expectations.call(hash_or_value) if expectations.class == Proc
|
131
|
+
|
121
132
|
expectations.each do |prop_name, expected_type|
|
122
|
-
value = expected_type == :date ? convert_to_date(
|
133
|
+
value = expected_type == :date ? convert_to_date(hash_or_value[prop_name]) : hash_or_value[prop_name]
|
123
134
|
expected_class = expected_type.class
|
124
135
|
value_class = value.class
|
136
|
+
|
125
137
|
next expect_json_types_impl(expected_type, value) if is_hash?(expected_class)
|
126
138
|
next expected_type.call(value) if expected_class == Proc
|
139
|
+
|
127
140
|
if expected_type.to_s.include?("array_of")
|
128
141
|
check_array_types(value, value_class, prop_name, expected_type)
|
129
142
|
else
|
@@ -177,6 +190,30 @@ module Airborne
|
|
177
190
|
end
|
178
191
|
end
|
179
192
|
|
193
|
+
# Convert integers in `old_expectations` to proc
|
194
|
+
#
|
195
|
+
# @param old_expectations [Hash]
|
196
|
+
def convert_expectations_for_json_sizes(old_expectations)
|
197
|
+
unless old_expectations.is_a?(Hash)
|
198
|
+
return convert_expectation_for_json_sizes(old_expectations)
|
199
|
+
end
|
200
|
+
|
201
|
+
old_expectations.each_with_object({}) do |(prop_name, expected_size), memo|
|
202
|
+
new_value = if expected_size.is_a?(Hash)
|
203
|
+
convert_expectations_for_json_sizes(expected_size)
|
204
|
+
else
|
205
|
+
convert_expectation_for_json_sizes(expected_size)
|
206
|
+
end
|
207
|
+
memo[prop_name] = new_value
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# @param expected_size [Integer]
|
212
|
+
# @return [Proc]
|
213
|
+
def convert_expectation_for_json_sizes(expected_size)
|
214
|
+
-> (data) { expect(data.size).to eq(expected_size) }
|
215
|
+
end
|
216
|
+
|
180
217
|
def is_property?(expectations)
|
181
218
|
[String, Regexp, Float, Fixnum, Bignum, TrueClass, FalseClass, NilClass].include?(expectations.class)
|
182
219
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'expect_json_sizes' do
|
4
|
+
|
5
|
+
it 'should detect sizes' do
|
6
|
+
mock_get('array_of_values')
|
7
|
+
get '/array_of_values'
|
8
|
+
expect_json_sizes({grades: 4, bad: 3, emptyArray: 0})
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should allow full object graph' do
|
12
|
+
mock_get('array_with_nested')
|
13
|
+
get '/array_with_nested'
|
14
|
+
expect_json_sizes({cars: {0 => {owners: 1}, 1 => {owners: 1}}})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should allow properties to be tested against a path' do
|
18
|
+
mock_get('array_with_nested')
|
19
|
+
get '/array_with_nested'
|
20
|
+
expect_json_sizes('cars.0.owners', 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should test against all elements in the array when path contains * AND expectation is an Integer' do
|
24
|
+
mock_get('array_with_nested')
|
25
|
+
get '/array_with_nested'
|
26
|
+
expect_json_sizes('cars.*.owners', 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should test against all elements in the array when path contains * AND expectation is a Hash' do
|
30
|
+
mock_get('array_with_nested')
|
31
|
+
get '/array_with_nested'
|
32
|
+
expect_json_sizes('cars.*', {owners: 1})
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/airborne/expectations/{expect_json_types_date.rb → expect_json_types_date_spec.rb}
RENAMED
File without changes
|
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.2
|
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: 2014-
|
12
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- ".coveralls.yml"
|
111
111
|
- ".gitignore"
|
112
112
|
- ".travis.yml"
|
113
|
+
- CHANGELOG.md
|
113
114
|
- Gemfile
|
114
115
|
- Gemfile.lock
|
115
116
|
- LICENSE
|
@@ -131,8 +132,9 @@ files:
|
|
131
132
|
- spec/airborne/expectations/expect_json_lambda_spec.rb
|
132
133
|
- spec/airborne/expectations/expect_json_path_spec.rb
|
133
134
|
- spec/airborne/expectations/expect_json_regex_spec.rb
|
135
|
+
- spec/airborne/expectations/expect_json_sizes_spec.rb
|
134
136
|
- spec/airborne/expectations/expect_json_spec.rb
|
135
|
-
- spec/airborne/expectations/
|
137
|
+
- spec/airborne/expectations/expect_json_types_date_spec.rb
|
136
138
|
- spec/airborne/expectations/expect_json_types_lambda_spec.rb
|
137
139
|
- spec/airborne/expectations/expect_json_types_optional_spec.rb
|
138
140
|
- spec/airborne/expectations/expect_json_types_path_spec.rb
|
@@ -178,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
180
|
version: '0'
|
179
181
|
requirements: []
|
180
182
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.1.5
|
182
184
|
signing_key:
|
183
185
|
specification_version: 4
|
184
186
|
summary: RSpec driven API testing framework
|