airborne 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- 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,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect_status' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should verify correct status code' do
|
5
|
+
mock_get('simple_get')
|
6
|
+
get '/simple_get'
|
7
|
+
expect_status(200)
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it 'should fail when incorrect status code is returned' do
|
11
|
+
mock_get('simple_get')
|
12
|
+
get '/simple_get'
|
13
|
+
expect{expect_status(123)}.to raise_error
|
14
|
+
end
|
15
15
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'expect header' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should find exact match for header content' do
|
5
|
+
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
6
|
+
get '/simple_get'
|
7
|
+
expect_header(:content_type, 'application/json')
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it 'should ensure correct headers are present' do
|
11
|
+
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
12
|
+
get '/simple_get'
|
13
|
+
expect{expect_header(:foo, 'bar')}.to raise_error
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'expect header contains' do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
it 'should ensure partial header match exists' do
|
19
|
+
mock_get('simple_get', {'Content-Type' => 'application/json'})
|
20
|
+
get '/simple_get'
|
21
|
+
expect_header_contains(:content_type, 'json')
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
35
35
|
end
|
data/spec/airborne/patch_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'patch' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should allow testing on patch requests' do
|
5
|
+
mock_patch('simple_patch')
|
6
|
+
patch '/simple_patch', {}
|
7
|
+
expect_json_types({status: :string, someNumber: :int})
|
8
|
+
end
|
9
9
|
end
|
data/spec/airborne/post_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'post' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should allow testing on post requests' do
|
5
|
+
mock_post('simple_post')
|
6
|
+
post '/simple_post', {}
|
7
|
+
expect_json_types({status: :string, someNumber: :int})
|
8
|
+
end
|
9
9
|
end
|
data/spec/airborne/put_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'put' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it 'should allow testing on put requests' do
|
5
|
+
mock_put('simple_put')
|
6
|
+
put '/simple_put', {}
|
7
|
+
expect_json_types({status: :string, someNumber: :int})
|
8
|
+
end
|
9
9
|
end
|
@@ -2,26 +2,26 @@ require 'json'
|
|
2
2
|
require 'sinatra'
|
3
3
|
|
4
4
|
class SampleApp < Sinatra::Application
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
before do
|
6
|
+
content_type 'application/json'
|
7
|
+
end
|
8
|
+
get '/' do
|
9
|
+
{foo: "bar"}.to_json
|
10
|
+
end
|
11
11
|
end
|
12
12
|
|
13
13
|
Airborne.configure do |config|
|
14
|
-
|
14
|
+
config.rack_app = SampleApp
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'rack app' do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
it 'should allow requests against a sinatra app' do
|
19
|
+
get '/'
|
20
|
+
expect_json_types({foo: :string})
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
27
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/stub_helper.rb
CHANGED
@@ -2,36 +2,36 @@ require 'webmock/rspec'
|
|
2
2
|
|
3
3
|
module StubHelper
|
4
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
|
-
|
5
|
+
def initialize
|
6
|
+
@base_url = 'http://www.example.com/'
|
7
|
+
end
|
8
|
+
|
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
|
+
end
|
12
|
+
|
13
|
+
def mock_post(url, options = {}, status = 200)
|
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), status: status)
|
16
|
+
end
|
17
|
+
|
18
|
+
def mock_put(url, options = {}, status = 200)
|
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), status: status)
|
21
|
+
end
|
22
|
+
|
23
|
+
def mock_patch(url, options = {}, status = 200)
|
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), status: status)
|
26
|
+
end
|
27
|
+
|
28
|
+
def mock_delete(url)
|
29
|
+
stub_request(:delete, @base_url + url)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get_json_response_file(name)
|
35
|
+
IO.read(File.join('spec/test_responses', name + ".json"))
|
36
|
+
end
|
37
37
|
end
|
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.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Friedman
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.2.0
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: RSpec driven API testing framework
|