airborne 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/Gemfile +5 -1
- data/Gemfile.lock +43 -0
- data/README.md +33 -7
- data/airborne.gemspec +3 -1
- data/lib/airborne.rb +6 -0
- data/lib/airborne/base.rb +17 -28
- data/lib/airborne/rack_test_requester.rb +11 -0
- data/lib/airborne/request_expectations.rb +0 -2
- data/lib/airborne/rest_client_requester.rb +26 -0
- data/spec/airborne/base_spec.rb +21 -2
- data/spec/airborne/expect_json_spec.rb +6 -0
- data/spec/airborne/expect_json_types_spec.rb +6 -0
- data/spec/airborne/headers_spec.rb +12 -0
- data/spec/airborne/rack_sinatra_spec.rb +27 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/stub_helper.rb +8 -8
- data/spec/test_responses/invalid_get.json +1 -0
- metadata +47 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2333bbac632fbb30333040aa0aa6bab7dc691118
|
4
|
+
data.tar.gz: 4bf80a6bc014b5d8fb7a41943ad53299670a111b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 014872f890830f5941401069bb62d17a1fb3006d3bb92125be375c2f32f114fc801f0edd26a3c9bee8e0fe16e7c997aeb6d509508c9c68fb27fc89a691fca826
|
7
|
+
data.tar.gz: 02d23b76acb06cb0032ec63847bfaa9d06d1edb473e84d32d3e97fdf1307e197158f3e495ec2ede44df5ae01c5fc5ac9561719feca6a7a66d6ed491a0719c762
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,34 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (4.1.6)
|
5
|
+
i18n (~> 0.6, >= 0.6.9)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 1.1)
|
4
10
|
addressable (2.3.6)
|
11
|
+
coveralls (0.7.1)
|
12
|
+
multi_json (~> 1.3)
|
13
|
+
rest-client
|
14
|
+
simplecov (>= 0.7)
|
15
|
+
term-ansicolor
|
16
|
+
thor
|
5
17
|
crack (0.4.2)
|
6
18
|
safe_yaml (~> 1.0.0)
|
7
19
|
diff-lcs (1.2.5)
|
20
|
+
docile (1.1.5)
|
21
|
+
i18n (0.6.11)
|
22
|
+
json (1.8.1)
|
8
23
|
mime-types (2.3)
|
24
|
+
minitest (5.4.1)
|
25
|
+
multi_json (1.10.1)
|
9
26
|
netrc (0.7.7)
|
27
|
+
rack (1.5.2)
|
28
|
+
rack-protection (1.5.3)
|
29
|
+
rack
|
30
|
+
rack-test (0.6.2)
|
31
|
+
rack (>= 1.0)
|
10
32
|
rest-client (1.7.2)
|
11
33
|
mime-types (>= 1.16, < 3.0)
|
12
34
|
netrc (~> 0.7)
|
@@ -23,6 +45,23 @@ GEM
|
|
23
45
|
rspec-support (~> 3.1.0)
|
24
46
|
rspec-support (3.1.0)
|
25
47
|
safe_yaml (1.0.3)
|
48
|
+
simplecov (0.9.0)
|
49
|
+
docile (~> 1.1.0)
|
50
|
+
multi_json
|
51
|
+
simplecov-html (~> 0.8.0)
|
52
|
+
simplecov-html (0.8.0)
|
53
|
+
sinatra (1.4.5)
|
54
|
+
rack (~> 1.4)
|
55
|
+
rack-protection (~> 1.4)
|
56
|
+
tilt (~> 1.3, >= 1.3.4)
|
57
|
+
term-ansicolor (1.3.0)
|
58
|
+
tins (~> 1.0)
|
59
|
+
thor (0.19.1)
|
60
|
+
thread_safe (0.3.4)
|
61
|
+
tilt (1.4.1)
|
62
|
+
tins (1.3.3)
|
63
|
+
tzinfo (1.2.2)
|
64
|
+
thread_safe (~> 0.1)
|
26
65
|
webmock (1.18.0)
|
27
66
|
addressable (>= 2.3.6)
|
28
67
|
crack (>= 0.3.2)
|
@@ -31,6 +70,10 @@ PLATFORMS
|
|
31
70
|
ruby
|
32
71
|
|
33
72
|
DEPENDENCIES
|
73
|
+
activesupport
|
74
|
+
coveralls
|
75
|
+
rack-test
|
34
76
|
rest-client
|
35
77
|
rspec
|
78
|
+
sinatra
|
36
79
|
webmock
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Airborne
|
2
2
|
|
3
3
|
[![airborne travis](http://img.shields.io/travis/brooklynDev/airborne.svg?branch=master&style=flat-square)](https://travis-ci.org/brooklynDev/airborne)
|
4
|
+
[![airborne coveralls](http://img.shields.io/coveralls/brooklynDev/airborne/master.svg?style=flat-square)](https://coveralls.io/r/brooklynDev/airborne?branch=master)
|
4
5
|
[![airborne gem version](http://img.shields.io/gem/v/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)
|
5
6
|
[![airbore gem downloads](http://img.shields.io/gem/dt/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)
|
6
7
|
[![airborne gem stable downloads](http://img.shields.io/gem/dv/airborne/stable.svg?style=flat-square)](http://rubygems.org/gems/airborne)
|
@@ -66,7 +67,7 @@ Additionally, if an entire object could be null, but you'd still want to test th
|
|
66
67
|
```ruby
|
67
68
|
it 'should allow optional nested hash' do
|
68
69
|
get '/simple_path_get' #may or may not return coordinates
|
69
|
-
expect_json_types("address.coordinates", optional({
|
70
|
+
expect_json_types("address.coordinates", optional({latitude: :float, longitude: :float}))
|
70
71
|
end
|
71
72
|
```
|
72
73
|
|
@@ -90,7 +91,7 @@ Airborne uses `rest_client` to make the HTTP request, and supports all HTTP verb
|
|
90
91
|
* `body` - The raw HTTP body returned from the request
|
91
92
|
* `json_body` - A symbolized hash representation of the JSON returned by the request
|
92
93
|
|
93
|
-
|
94
|
+
For example:
|
94
95
|
|
95
96
|
```ruby
|
96
97
|
it 'should validate types' do
|
@@ -111,6 +112,18 @@ For requests that require a body (`post`, `put`, `patch`) you can pass the body
|
|
111
112
|
```ruby
|
112
113
|
post 'http://example.com/api/v1/my_api', {:name => 'John Doe'}, {'x-auth-token' => 'my_token'}
|
113
114
|
```
|
115
|
+
|
116
|
+
##Testing Rack Applications
|
117
|
+
|
118
|
+
If you have an existing Rack application like `sinatra` or `grape` you can run Airborne against your application and test without actually having a server running. To do that, just specify your rack application in your Airborne configuration:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
Airborne.configure do |config|
|
122
|
+
config.rack_app = MySinatraApp
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
Under the covers, Airborne uses [rack-test](https://github.com/brynary/rack-test) to make the requests. (Rails applications are still not working correctly, support for Rails will come soon!)
|
114
127
|
|
115
128
|
##API
|
116
129
|
|
@@ -123,7 +136,7 @@ post 'http://example.com/api/v1/my_api', {:name => 'John Doe'}, {'x-auth-token'
|
|
123
136
|
|
124
137
|
##Path Matching
|
125
138
|
|
126
|
-
When calling `expect_json_types`, `expect_json` or `expect_json_keys` you can
|
139
|
+
When calling `expect_json_types`, `expect_json` or `expect_json_keys` you can optionally specify a path as a first parameter.
|
127
140
|
|
128
141
|
For example, if our API returns the following JSON:
|
129
142
|
|
@@ -135,7 +148,7 @@ For example, if our API returns the following JSON:
|
|
135
148
|
"city": "Roswell",
|
136
149
|
"state": "NM",
|
137
150
|
"coordinates": {
|
138
|
-
"
|
151
|
+
"latitude": 33.3872,
|
139
152
|
"longitude": 104.5281
|
140
153
|
}
|
141
154
|
}
|
@@ -150,17 +163,25 @@ describe 'path spec' do
|
|
150
163
|
get 'http://example.com/api/v1/simple_path_get'
|
151
164
|
expect_json_types('address', {street: :string, city: :string, state: :string, coordinates: :object })
|
152
165
|
#or this
|
153
|
-
expect_json_types('address', {street: :string, city: :string, state: :string, coordinates: {
|
166
|
+
expect_json_types('address', {street: :string, city: :string, state: :string, coordinates: { latitude: :float, longitude: :float } })
|
154
167
|
end
|
155
168
|
end
|
156
169
|
```
|
170
|
+
Or, to test the existence of specific keys:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
it 'should allow nested paths' do
|
174
|
+
get 'http://example.com/api/v1/simple_path_get'
|
175
|
+
expect_json_keys('address', [:street, :city, :state, :coordinates])
|
176
|
+
end
|
177
|
+
```
|
157
178
|
|
158
179
|
Alternativley, if we only want to test `coordinates` we can dot into just the `coordinates`:
|
159
180
|
|
160
181
|
```ruby
|
161
182
|
it 'should allow nested paths' do
|
162
183
|
get 'http://example.com/api/v1/simple_path_get'
|
163
|
-
expect_json('address.coordinates', {
|
184
|
+
expect_json('address.coordinates', {latitude: 33.3872, longitude: 104.5281} )
|
164
185
|
end
|
165
186
|
```
|
166
187
|
|
@@ -249,7 +270,7 @@ Airborne.configure.do |config|
|
|
249
270
|
end
|
250
271
|
```
|
251
272
|
|
252
|
-
Additionally, you can specify a `base_url` and default `headers` to be used on every request (unless
|
273
|
+
Additionally, you can specify a `base_url` and default `headers` to be used on every request (unless overridden in the actual request):
|
253
274
|
|
254
275
|
```ruby
|
255
276
|
Airborne.configure.do |config|
|
@@ -265,6 +286,11 @@ describe 'spec' do
|
|
265
286
|
end
|
266
287
|
```
|
267
288
|
|
289
|
+
### Run it from the CLI
|
290
|
+
|
291
|
+
$ cd your/project
|
292
|
+
$ rspec spec
|
293
|
+
|
268
294
|
## License
|
269
295
|
|
270
296
|
The MIT License
|
data/airborne.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'airborne'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.19'
|
4
4
|
s.date = '2014-09-12'
|
5
5
|
s.summary = "RSpec driven API testing framework"
|
6
6
|
s.authors = ["Alex Friedman", "Seth Pollack"]
|
@@ -10,5 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.license = 'MIT'
|
11
11
|
s.add_runtime_dependency 'rspec', '~> 3.1', '>= 3.1.0'
|
12
12
|
s.add_runtime_dependency 'rest-client', '~> 1.7', '>= 1.7.2'
|
13
|
+
s.add_runtime_dependency 'rack-test', '~> 0.6', '>= 0.6.2'
|
14
|
+
s.add_runtime_dependency 'activesupport', '~> 4.1.6', '>= 4.1.6'
|
13
15
|
s.add_development_dependency 'webmock', '~> 0'
|
14
16
|
end
|
data/lib/airborne.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
require 'airborne/optional_hash_type_expectations'
|
2
2
|
require 'airborne/path_matcher'
|
3
3
|
require 'airborne/request_expectations'
|
4
|
+
require 'airborne/rest_client_requester'
|
5
|
+
require 'airborne/rack_test_requester'
|
4
6
|
require 'airborne/base'
|
5
7
|
|
8
|
+
|
6
9
|
RSpec.configure do |config|
|
7
10
|
config.include Airborne
|
8
11
|
config.add_setting :base_url
|
9
12
|
config.add_setting :headers
|
13
|
+
config.add_setting :rack_app
|
14
|
+
config.add_setting :requester_type
|
15
|
+
config.add_setting :requester_module
|
10
16
|
end
|
data/lib/airborne/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'rest_client'
|
2
1
|
require 'json'
|
2
|
+
require 'active_support/core_ext'
|
3
3
|
|
4
4
|
module Airborne
|
5
5
|
include RequestExpectations
|
@@ -10,28 +10,38 @@ module Airborne
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.included(base)
|
14
|
+
if(!Airborne.configuration.requester_module.nil?)
|
15
|
+
base.send(:include, Airborne.configuration.requester_module)
|
16
|
+
elsif(!Airborne.configuration.rack_app.nil?)
|
17
|
+
base.send(:include, RackTestRequester)
|
18
|
+
else
|
19
|
+
base.send(:include, RestClientRequester)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
def self.configuration
|
14
24
|
RSpec.configuration
|
15
25
|
end
|
16
26
|
|
17
27
|
def get(url, headers = nil)
|
18
|
-
make_request(:get, url, {headers: headers})
|
28
|
+
set_response(make_request(:get, url, {headers: headers}))
|
19
29
|
end
|
20
30
|
|
21
31
|
def post(url, post_body = nil, headers = nil)
|
22
|
-
make_request(:post, url, {body: post_body, headers: headers})
|
32
|
+
set_response(make_request(:post, url, {body: post_body, headers: headers}))
|
23
33
|
end
|
24
34
|
|
25
35
|
def patch(url, patch_body = nil, headers = nil )
|
26
|
-
make_request(:patch, url, {body: patch_body, headers: headers})
|
36
|
+
set_response(make_request(:patch, url, {body: patch_body, headers: headers}))
|
27
37
|
end
|
28
38
|
|
29
39
|
def put(url, put_body = nil, headers = nil )
|
30
|
-
make_request(:put, url, {body: put_body, headers: headers})
|
40
|
+
set_response(make_request(:put, url, {body: put_body, headers: headers}))
|
31
41
|
end
|
32
42
|
|
33
43
|
def delete(url, headers = nil)
|
34
|
-
make_request(:delete, url, {headers: headers})
|
44
|
+
set_response(make_request(:delete, url, {headers: headers}))
|
35
45
|
end
|
36
46
|
|
37
47
|
def response
|
@@ -52,27 +62,6 @@ module Airborne
|
|
52
62
|
|
53
63
|
private
|
54
64
|
|
55
|
-
def make_request(method, url, options = {})
|
56
|
-
headers = (options[:headers] || {}).merge({content_type: :json})
|
57
|
-
base_headers = Airborne.configuration.headers || {}
|
58
|
-
headers = base_headers.merge(headers)
|
59
|
-
res = if method == :post || method == :patch || method == :put
|
60
|
-
begin
|
61
|
-
RestClient.send(method, get_url(url), options[:body].nil? ? "" : options[:body].to_json, headers)
|
62
|
-
rescue RestClient::Exception => e
|
63
|
-
e.response
|
64
|
-
end
|
65
|
-
else
|
66
|
-
begin
|
67
|
-
RestClient.send(method, get_url(url), headers)
|
68
|
-
rescue RestClient::Exception => e
|
69
|
-
e.response
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
set_response(res)
|
74
|
-
end
|
75
|
-
|
76
65
|
def get_url(url)
|
77
66
|
base = Airborne.configuration.base_url || ""
|
78
67
|
base + url
|
@@ -81,7 +70,7 @@ module Airborne
|
|
81
70
|
def set_response(res)
|
82
71
|
@response = res
|
83
72
|
@body = res.body
|
84
|
-
@headers = res.headers
|
73
|
+
@headers = HashWithIndifferentAccess.new(res.headers.deep_symbolize_keys) unless res.headers.nil?
|
85
74
|
begin
|
86
75
|
@json_body = JSON.parse(res.body, symbolize_names: true) unless res.body.empty?
|
87
76
|
rescue
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
3
|
+
module Airborne
|
4
|
+
module RackTestRequester
|
5
|
+
def make_request(method, url, options = {})
|
6
|
+
browser = Rack::Test::Session.new(Rack::MockSession.new(Airborne.configuration.rack_app))
|
7
|
+
browser.send(method, url, options[:body] || {}, options[:headers] || {})
|
8
|
+
browser.last_response
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -29,7 +29,6 @@ module Airborne
|
|
29
29
|
|
30
30
|
def expect_header(key, content)
|
31
31
|
header = headers[key]
|
32
|
-
expect(header).to_not be_nil
|
33
32
|
if header
|
34
33
|
expect(header.downcase).to eq(content.downcase)
|
35
34
|
else
|
@@ -39,7 +38,6 @@ module Airborne
|
|
39
38
|
|
40
39
|
def expect_header_contains(key, content)
|
41
40
|
header = headers[key]
|
42
|
-
expect(header).to_not be_nil
|
43
41
|
if header
|
44
42
|
expect(header.downcase).to include(content.downcase)
|
45
43
|
else
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
module Airborne
|
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
|
+
|
22
|
+
end
|
23
|
+
res
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/airborne/base_spec.rb
CHANGED
@@ -13,11 +13,12 @@ describe 'base spec' do
|
|
13
13
|
expect(headers).to_not be(nil)
|
14
14
|
end
|
15
15
|
|
16
|
-
it 'when request is made headers should be
|
16
|
+
it 'when request is made headers should be hash with indifferent access' do
|
17
17
|
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
18
18
|
get '/simple_get'
|
19
19
|
expect(headers).to be_kind_of(Hash)
|
20
|
-
expect(headers
|
20
|
+
expect(headers[:content_type]).to eq('application/json')
|
21
|
+
expect(headers['content_type']).to eq('application/json')
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'when request is made body should be set' do
|
@@ -32,4 +33,22 @@ describe 'base spec' do
|
|
32
33
|
expect(json_body).to be_kind_of(Hash)
|
33
34
|
expect(json_body.first[0]).to be_kind_of(Symbol)
|
34
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
|
35
54
|
end
|
@@ -18,6 +18,12 @@ describe 'expect_json' do
|
|
18
18
|
get '/simple_path_get'
|
19
19
|
expect_json('address', {street: "Area 51", city: "Roswell", state: "NM"})
|
20
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
|
21
27
|
|
22
28
|
it 'should allow nested paths' do
|
23
29
|
mock_get('simple_nested_path')
|
@@ -25,6 +25,12 @@ describe 'expect_json_types' do
|
|
25
25
|
expect_json_types('address', {street: :string, city: :string, state: :string})
|
26
26
|
end
|
27
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
|
+
|
28
34
|
it 'should allow nested paths' do
|
29
35
|
mock_get('simple_nested_path')
|
30
36
|
get '/simple_nested_path'
|
@@ -20,4 +20,16 @@ describe 'expect header contains' do
|
|
20
20
|
get '/simple_get'
|
21
21
|
expect_header_contains(:content_type, 'json')
|
22
22
|
end
|
23
|
+
|
24
|
+
it 'should ensure header is present' do
|
25
|
+
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
26
|
+
get '/simple_get'
|
27
|
+
expect{expect_header_contains(:foo, 'bar')}.to raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should ensure partial header is present' do
|
31
|
+
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
32
|
+
get '/simple_get'
|
33
|
+
expect{expect_header_contains(:content_type, 'bar')}.to raise_error
|
34
|
+
end
|
23
35
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
class SampleApp < Sinatra::Application
|
5
|
+
before do
|
6
|
+
content_type 'application/json'
|
7
|
+
end
|
8
|
+
get '/' do
|
9
|
+
{foo: "bar"}.to_json
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Airborne.configure do |config|
|
14
|
+
config.rack_app = SampleApp
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'rack app' do
|
18
|
+
it 'should allow requests against a sinatra app' do
|
19
|
+
get '/'
|
20
|
+
expect_json_types({foo: :string})
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should ensure correct values from sinatra app' do
|
24
|
+
get '/'
|
25
|
+
expect{expect_json_types({foo: :int})}.to raise_error
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/stub_helper.rb
CHANGED
@@ -6,23 +6,23 @@ module StubHelper
|
|
6
6
|
@base_url = 'http://www.example.com/'
|
7
7
|
end
|
8
8
|
|
9
|
-
def mock_get(url, response_headers = {})
|
10
|
-
stub_request(:get, @base_url + url).to_return(headers: response_headers, body: get_json_response_file(url))
|
9
|
+
def mock_get(url, response_headers = {}, status = 200)
|
10
|
+
stub_request(:get, @base_url + url).to_return(headers: response_headers, body: get_json_response_file(url), status: status)
|
11
11
|
end
|
12
12
|
|
13
|
-
def mock_post(url, options = {})
|
13
|
+
def mock_post(url, options = {}, status = 200)
|
14
14
|
stub_request(:post, @base_url + url).with(body: options[:request_body] || {})
|
15
|
-
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url))
|
15
|
+
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
|
16
16
|
end
|
17
17
|
|
18
|
-
def mock_put(url, options = {})
|
18
|
+
def mock_put(url, options = {}, status = 200)
|
19
19
|
stub_request(:put, @base_url + url).with(body: options[:request_body] || {})
|
20
|
-
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url))
|
20
|
+
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
|
21
21
|
end
|
22
22
|
|
23
|
-
def mock_patch(url, options = {})
|
23
|
+
def mock_patch(url, options = {}, status = 200)
|
24
24
|
stub_request(:patch, @base_url + url).with(body: options[:request_body] || {})
|
25
|
-
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url))
|
25
|
+
.to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
|
26
26
|
end
|
27
27
|
|
28
28
|
def mock_delete(url)
|
@@ -0,0 +1 @@
|
|
1
|
+
THIS IS INTENTIONALLY NOT JSON
|
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.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Friedman
|
@@ -51,6 +51,46 @@ dependencies:
|
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 1.7.2
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rack-test
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.6'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.6.2
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.6'
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.6.2
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: activesupport
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 4.1.6
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 4.1.6
|
84
|
+
type: :runtime
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 4.1.6
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 4.1.6
|
54
94
|
- !ruby/object:Gem::Dependency
|
55
95
|
name: webmock
|
56
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,6 +113,7 @@ executables: []
|
|
73
113
|
extensions: []
|
74
114
|
extra_rdoc_files: []
|
75
115
|
files:
|
116
|
+
- ".coveralls.yml"
|
76
117
|
- ".gitignore"
|
77
118
|
- ".travis.yml"
|
78
119
|
- Gemfile
|
@@ -84,7 +125,9 @@ files:
|
|
84
125
|
- lib/airborne/base.rb
|
85
126
|
- lib/airborne/optional_hash_type_expectations.rb
|
86
127
|
- lib/airborne/path_matcher.rb
|
128
|
+
- lib/airborne/rack_test_requester.rb
|
87
129
|
- lib/airborne/request_expectations.rb
|
130
|
+
- lib/airborne/rest_client_requester.rb
|
88
131
|
- spec/airborne/base_spec.rb
|
89
132
|
- spec/airborne/delete_spec.rb
|
90
133
|
- spec/airborne/expect_json_keys_spec.rb
|
@@ -95,6 +138,7 @@ files:
|
|
95
138
|
- spec/airborne/patch_spec.rb
|
96
139
|
- spec/airborne/post_spec.rb
|
97
140
|
- spec/airborne/put_spec.rb
|
141
|
+
- spec/airborne/rack_sinatra_spec.rb
|
98
142
|
- spec/spec_helper.rb
|
99
143
|
- spec/stub_helper.rb
|
100
144
|
- spec/test_responses/array_of_values.json
|
@@ -102,6 +146,7 @@ files:
|
|
102
146
|
- spec/test_responses/array_with_index.json
|
103
147
|
- spec/test_responses/array_with_nested.json
|
104
148
|
- spec/test_responses/array_with_nested_bad_data.json
|
149
|
+
- spec/test_responses/invalid_get.json
|
105
150
|
- spec/test_responses/simple_get.json
|
106
151
|
- spec/test_responses/simple_json.json
|
107
152
|
- spec/test_responses/simple_nested_path.json
|
@@ -129,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
174
|
version: '0'
|
130
175
|
requirements: []
|
131
176
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.1.5
|
133
178
|
signing_key:
|
134
179
|
specification_version: 4
|
135
180
|
summary: RSpec driven API testing framework
|