airborne 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac06c0189febbd0649871cf9919a66e2d8cf2c82
|
4
|
+
data.tar.gz: ab35b7f94d89caabcdb9936f7f8ac9172c872b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd8d1a0d1b65801745f20d9a044341c884d00c5391290c4f5db2da9544d006722a247e0cb1edeb2ed9f3d33f4d29ab5a8d17bf8b77c11af4f4d3834cf596c4b4
|
7
|
+
data.tar.gz: 94615d3ca58942930f91208d83c7740184631bbb5bbd44dc5db12582f2ce68ec49684103dab23e44ecae30fe002a793b4ca75eddd73aa8d13d053f7232526c57
|
data/README.md
CHANGED
@@ -137,6 +137,12 @@ For requests that require a body (`post`, `put`, `patch`) you can pass the body
|
|
137
137
|
post 'http://example.com/api/v1/my_api', {:name => 'John Doe'}, {'x-auth-token' => 'my_token'}
|
138
138
|
```
|
139
139
|
|
140
|
+
For requests that require Query params you can pass a params hash into headers.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
post 'http://example.com/api/v1/my_api', {}, {'params' => {'param_key' => 'param_value'}
|
144
|
+
```
|
145
|
+
|
140
146
|
##Testing Rack Applications
|
141
147
|
|
142
148
|
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:
|
data/airborne.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'airborne'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.16'
|
4
4
|
s.date = '2015-03-03'
|
5
|
-
s.summary =
|
6
|
-
s.authors = [
|
5
|
+
s.summary = 'RSpec driven API testing framework'
|
6
|
+
s.authors = ['Alex Friedman', 'Seth Pollack']
|
7
7
|
s.email = ['a.friedman07@gmail.com', 'teampollack@gmail.com']
|
8
8
|
s.require_paths = ['lib']
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.license = 'MIT'
|
11
11
|
s.add_runtime_dependency 'rspec', '~> 3.1', '>= 3.1.0'
|
12
|
-
s.add_runtime_dependency 'rest-client', '~> 1.7', '>= 1.7.3' #version 1.7.3 fixes security vulnerability https://github.com/brooklynDev/airborne/issues/41
|
12
|
+
s.add_runtime_dependency 'rest-client', '~> 1.7', '>= 1.7.3' # version 1.7.3 fixes security vulnerability https://github.com/brooklynDev/airborne/issues/41
|
13
13
|
s.add_runtime_dependency 'rack-test', '~> 0.6', '>= 0.6.2'
|
14
14
|
s.add_runtime_dependency 'activesupport', '>= 3.0.0', '>= 3.0.0'
|
15
15
|
s.add_development_dependency 'webmock', '~> 0'
|
data/lib/airborne.rb
CHANGED
@@ -5,7 +5,6 @@ require 'airborne/rest_client_requester'
|
|
5
5
|
require 'airborne/rack_test_requester'
|
6
6
|
require 'airborne/base'
|
7
7
|
|
8
|
-
|
9
8
|
RSpec.configure do |config|
|
10
9
|
config.include Airborne
|
11
10
|
config.add_setting :base_url
|
@@ -13,4 +12,4 @@ RSpec.configure do |config|
|
|
13
12
|
config.add_setting :rack_app
|
14
13
|
config.add_setting :requester_type
|
15
14
|
config.add_setting :requester_module
|
16
|
-
end
|
15
|
+
end
|
data/lib/airborne/base.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'active_support
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
4
|
|
4
5
|
module Airborne
|
5
6
|
class InvalidJsonError < StandardError; end
|
7
|
+
|
6
8
|
include RequestExpectations
|
9
|
+
|
10
|
+
attr_reader :response, :headers, :body
|
11
|
+
|
7
12
|
def self.configure
|
8
13
|
RSpec.configure do |config|
|
9
14
|
yield config
|
@@ -11,9 +16,9 @@ module Airborne
|
|
11
16
|
end
|
12
17
|
|
13
18
|
def self.included(base)
|
14
|
-
if
|
19
|
+
if !Airborne.configuration.requester_module.nil?
|
15
20
|
base.send(:include, Airborne.configuration.requester_module)
|
16
|
-
elsif
|
21
|
+
elsif !Airborne.configuration.rack_app.nil?
|
17
22
|
base.send(:include, RackTestRequester)
|
18
23
|
else
|
19
24
|
base.send(:include, RestClientRequester)
|
@@ -25,54 +30,43 @@ module Airborne
|
|
25
30
|
end
|
26
31
|
|
27
32
|
def get(url, headers = nil)
|
28
|
-
set_response(make_request(:get, url,
|
33
|
+
set_response(make_request(:get, url, headers: headers))
|
29
34
|
end
|
30
35
|
|
31
36
|
def post(url, post_body = nil, headers = nil)
|
32
|
-
set_response(make_request(:post, url,
|
37
|
+
set_response(make_request(:post, url, body: post_body, headers: headers))
|
33
38
|
end
|
34
39
|
|
35
|
-
def patch(url, patch_body = nil, headers = nil
|
36
|
-
set_response(make_request(:patch, url,
|
40
|
+
def patch(url, patch_body = nil, headers = nil)
|
41
|
+
set_response(make_request(:patch, url, body: patch_body, headers: headers))
|
37
42
|
end
|
38
43
|
|
39
|
-
def put(url, put_body = nil, headers = nil
|
40
|
-
set_response(make_request(:put, url,
|
44
|
+
def put(url, put_body = nil, headers = nil)
|
45
|
+
set_response(make_request(:put, url, body: put_body, headers: headers))
|
41
46
|
end
|
42
47
|
|
43
48
|
def delete(url, headers = nil)
|
44
|
-
set_response(make_request(:delete, url,
|
49
|
+
set_response(make_request(:delete, url, headers: headers))
|
45
50
|
end
|
46
51
|
|
47
52
|
def head(url, headers = nil)
|
48
|
-
set_response(make_request(:head, url,
|
53
|
+
set_response(make_request(:head, url, headers: headers))
|
49
54
|
end
|
50
55
|
|
51
56
|
def options(url, headers = nil)
|
52
|
-
set_response(make_request(:options, url,
|
53
|
-
end
|
54
|
-
|
55
|
-
def response
|
56
|
-
@response
|
57
|
-
end
|
58
|
-
|
59
|
-
def headers
|
60
|
-
@headers
|
61
|
-
end
|
62
|
-
|
63
|
-
def body
|
64
|
-
@body
|
57
|
+
set_response(make_request(:options, url, headers: headers))
|
65
58
|
end
|
66
59
|
|
67
60
|
def json_body
|
68
|
-
|
61
|
+
set_response(@response) if @json_body.nil? && !@response.nil?
|
62
|
+
fail InvalidJsonError, 'Api request returned invalid json' unless @json_body
|
69
63
|
@json_body
|
70
64
|
end
|
71
65
|
|
72
66
|
private
|
73
67
|
|
74
68
|
def get_url(url)
|
75
|
-
base = Airborne.configuration.base_url ||
|
69
|
+
base = Airborne.configuration.base_url || ''
|
76
70
|
base + url
|
77
71
|
end
|
78
72
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Airborne
|
2
2
|
class PathError < StandardError; end
|
3
|
-
module PathMatcher
|
4
3
|
|
4
|
+
module PathMatcher
|
5
5
|
def get_by_path(path, json, &block)
|
6
|
-
|
6
|
+
fail PathError, "Invalid Path, contains '..'" if /\.\./ =~ path
|
7
7
|
type = false
|
8
8
|
parts = path.split('.')
|
9
9
|
parts.each_with_index do |part, index|
|
@@ -11,15 +11,14 @@ module Airborne
|
|
11
11
|
ensure_array(path, json)
|
12
12
|
type = part
|
13
13
|
if index < parts.length.pred
|
14
|
-
walk_with_path(type, index, path, parts, json, &block)
|
15
|
-
return
|
14
|
+
walk_with_path(type, index, path, parts, json, &block) && return
|
16
15
|
end
|
17
16
|
next
|
18
17
|
end
|
19
18
|
begin
|
20
19
|
json = process_json(part, json)
|
21
20
|
rescue
|
22
|
-
raise PathError, "Expected #{json.class}\nto
|
21
|
+
raise PathError, "Expected #{json.class}\nto be an object with property #{part}"
|
23
22
|
end
|
24
23
|
end
|
25
24
|
if type == '*'
|
@@ -51,7 +50,7 @@ module Airborne
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def process_json(part, json)
|
54
|
-
if
|
53
|
+
if index?(part) && json.is_a?(Array)
|
55
54
|
part = part.to_i
|
56
55
|
json = json[part]
|
57
56
|
else
|
@@ -60,7 +59,7 @@ module Airborne
|
|
60
59
|
json
|
61
60
|
end
|
62
61
|
|
63
|
-
def
|
62
|
+
def index?(part)
|
64
63
|
part =~ /^\d+$/
|
65
64
|
end
|
66
65
|
|
@@ -80,7 +79,7 @@ module Airborne
|
|
80
79
|
def expect_all(json, &block)
|
81
80
|
last_error = nil
|
82
81
|
begin
|
83
|
-
json.each{|part| yield part}
|
82
|
+
json.each { |part| yield part }
|
84
83
|
rescue Exception => e
|
85
84
|
last_error = e
|
86
85
|
end
|
@@ -88,16 +87,15 @@ module Airborne
|
|
88
87
|
end
|
89
88
|
|
90
89
|
def ensure_match_one(path, item_count, error_count)
|
91
|
-
|
90
|
+
fail RSpec::Expectations::ExpectationNotMetError, "Expected one object in path #{path} to match provided JSON values" if item_count == error_count
|
92
91
|
end
|
93
92
|
|
94
93
|
def ensure_match_all(error)
|
95
|
-
|
94
|
+
fail error unless error.nil?
|
96
95
|
end
|
97
96
|
|
98
97
|
def ensure_array(path, json)
|
99
|
-
|
98
|
+
fail RSpec::Expectations::ExpectationNotMetError, "Expected #{path} to be array got #{json.class} from JSON response" unless json.class == Array
|
100
99
|
end
|
101
|
-
|
102
100
|
end
|
103
101
|
end
|
@@ -7,6 +7,7 @@ module Airborne
|
|
7
7
|
base_headers = Airborne.configuration.headers || {}
|
8
8
|
headers = base_headers.merge(headers)
|
9
9
|
browser = Rack::Test::Session.new(Rack::MockSession.new(Airborne.configuration.rack_app))
|
10
|
+
headers.each { |name, value| browser.header(name, value) }
|
10
11
|
browser.send(method, url, options[:body] || {}, headers)
|
11
12
|
Rack::MockResponse.class_eval do
|
12
13
|
alias_method :code, :status
|
@@ -53,14 +53,14 @@ module Airborne
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def date
|
56
|
-
|
56
|
+
-> (value) { yield DateTime.parse(value) }
|
57
57
|
end
|
58
58
|
|
59
59
|
[:expect_json_types, :expect_json, :expect_json_keys, :expect_status, :expect_header, :expect_header_contains].each do |method_name|
|
60
60
|
method = instance_method(method_name)
|
61
61
|
define_method(method_name) do |*args, &block|
|
62
62
|
set_rails_response
|
63
|
-
method.bind(self).(*args, &block)
|
63
|
+
method.bind(self).call(*args, &block)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -75,7 +75,7 @@ module Airborne
|
|
75
75
|
expect(header.downcase).to eq(content.downcase)
|
76
76
|
end
|
77
77
|
else
|
78
|
-
|
78
|
+
fail RSpec::Expectations::ExpectationNotMetError, "Header #{key} not present in HTTP response"
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -95,12 +95,12 @@ module Airborne
|
|
95
95
|
|
96
96
|
def get_mapper
|
97
97
|
base_mapper = {
|
98
|
-
integer: [Fixnum,Bignum],
|
99
|
-
array_of_integers: [Fixnum,Bignum],
|
100
|
-
int: [Fixnum,Bignum],
|
101
|
-
array_of_ints: [Fixnum,Bignum],
|
102
|
-
float: [Float,Fixnum,Bignum],
|
103
|
-
array_of_floats: [Float,Fixnum,Bignum],
|
98
|
+
integer: [Fixnum, Bignum],
|
99
|
+
array_of_integers: [Fixnum, Bignum],
|
100
|
+
int: [Fixnum, Bignum],
|
101
|
+
array_of_ints: [Fixnum, Bignum],
|
102
|
+
float: [Float, Fixnum, Bignum],
|
103
|
+
array_of_floats: [Float, Fixnum, Bignum],
|
104
104
|
string: [String],
|
105
105
|
array_of_strings: [String],
|
106
106
|
boolean: [TrueClass, FalseClass],
|
@@ -111,18 +111,19 @@ module Airborne
|
|
111
111
|
array_of_objects: [Hash],
|
112
112
|
array: [Array],
|
113
113
|
array_of_arrays: [Array],
|
114
|
-
date: [DateTime]
|
114
|
+
date: [DateTime],
|
115
|
+
null: [NilClass]
|
115
116
|
}
|
116
117
|
|
117
118
|
mapper = base_mapper.clone
|
118
119
|
base_mapper.each do |key, value|
|
119
|
-
mapper[(key.to_s +
|
120
|
+
mapper[(key.to_s + '_or_null').to_sym] = value + [NilClass]
|
120
121
|
end
|
121
122
|
mapper
|
122
123
|
end
|
123
124
|
|
124
125
|
def expect_json_types_impl(expectations, hash_or_value)
|
125
|
-
return if
|
126
|
+
return if nil_optional_hash?(expectations, hash_or_value)
|
126
127
|
|
127
128
|
@mapper ||= get_mapper
|
128
129
|
|
@@ -138,10 +139,10 @@ module Airborne
|
|
138
139
|
expected_class = expected_type.class
|
139
140
|
value_class = value.class
|
140
141
|
|
141
|
-
next expect_json_types_impl(expected_type, value) if
|
142
|
+
next expect_json_types_impl(expected_type, value) if hash?(expected_class)
|
142
143
|
next expected_type.call(value) if expected_class == Proc
|
143
144
|
|
144
|
-
if expected_type.to_s.include?(
|
145
|
+
if expected_type.to_s.include?('array_of')
|
145
146
|
check_array_types(value, value_class, prop_name, expected_type)
|
146
147
|
else
|
147
148
|
expect_type(expected_type, value_class, prop_name)
|
@@ -151,7 +152,7 @@ module Airborne
|
|
151
152
|
|
152
153
|
def convert_to_date(value)
|
153
154
|
begin
|
154
|
-
|
155
|
+
DateTime.parse(value)
|
155
156
|
rescue
|
156
157
|
end
|
157
158
|
end
|
@@ -163,18 +164,19 @@ module Airborne
|
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
166
|
-
def
|
167
|
+
def nil_optional_hash?(expectations, hash)
|
167
168
|
expectations.class == Airborne::OptionalHashTypeExpectations && hash.nil?
|
168
169
|
end
|
169
170
|
|
170
171
|
def expect_type(expected_type, value_class, prop_name = nil)
|
171
|
-
insert = prop_name.nil? ?
|
172
|
+
insert = prop_name.nil? ? '' : "#{prop_name} to be of type"
|
172
173
|
msg = "Expected #{insert} #{expected_type}\n got #{value_class} instead"
|
174
|
+
fail ExpectationError, "Expected type #{expected_type}\nis an invalid type" if @mapper[expected_type].nil?
|
173
175
|
expect(@mapper[expected_type].include?(value_class)).to eq(true), msg
|
174
176
|
end
|
175
177
|
|
176
|
-
def
|
177
|
-
expected_class == Hash || expected_class ==
|
178
|
+
def hash?(expected_class)
|
179
|
+
expected_class == Hash || expected_class == Airborne::OptionalHashTypeExpectations
|
178
180
|
end
|
179
181
|
|
180
182
|
def expect_array(value_class, prop_name, expected_type)
|
@@ -183,11 +185,11 @@ module Airborne
|
|
183
185
|
|
184
186
|
def expect_json_impl(expectations, hash)
|
185
187
|
hash = hash.to_s if expectations.class == Regexp
|
186
|
-
return expect(hash).to match(expectations) if
|
188
|
+
return expect(hash).to match(expectations) if property?(expectations)
|
187
189
|
expectations.each do |prop_name, expected_value|
|
188
|
-
actual_value = ensure_hash_contains_prop(prop_name, hash) {hash[prop_name]}
|
190
|
+
actual_value = ensure_hash_contains_prop(prop_name, hash) { hash[prop_name] }
|
189
191
|
expected_class = expected_value.class
|
190
|
-
next
|
192
|
+
next expect(actual_value).to match(expected_value) if expected_class == Hash
|
191
193
|
next expected_value.call(actual_value) if expected_class == Proc
|
192
194
|
next expect(actual_value.to_s).to match(expected_value) if expected_class == Regexp
|
193
195
|
expect(actual_value).to eq(expected_value)
|
@@ -221,19 +223,12 @@ module Airborne
|
|
221
223
|
->(data) { expect(data.size).to eq(expected_size) }
|
222
224
|
end
|
223
225
|
|
224
|
-
def
|
226
|
+
def property?(expectations)
|
225
227
|
[String, Regexp, Float, Fixnum, Bignum, TrueClass, FalseClass, NilClass].include?(expectations.class)
|
226
228
|
end
|
227
229
|
|
228
|
-
# Resolve a supplied status to the appropriate class for the returned
|
229
|
-
# status being tested. This helps reduce brittleness due to '200' != 200
|
230
|
-
# when for the purposes of testing a response it is the same thing.
|
231
|
-
#
|
232
|
-
# @param candidate
|
233
|
-
# @param authority
|
234
|
-
# @return [String]
|
235
230
|
def resolve_status(candidate, authority)
|
236
|
-
candidate = Rack::Utils::SYMBOL_TO_STATUS_CODE[candidate] if candidate.
|
231
|
+
candidate = Rack::Utils::SYMBOL_TO_STATUS_CODE[candidate] if candidate.is_a?(Symbol)
|
237
232
|
case authority
|
238
233
|
when String then candidate.to_s
|
239
234
|
when Fixnum then candidate.to_i
|
@@ -3,26 +3,25 @@ require 'rest_client'
|
|
3
3
|
module Airborne
|
4
4
|
module RestClientRequester
|
5
5
|
def make_request(method, url, options = {})
|
6
|
-
headers = {content_type: :json}.merge(options[:headers] || {})
|
6
|
+
headers = { content_type: :json }.merge(options[:headers] || {})
|
7
7
|
base_headers = Airborne.configuration.headers || {}
|
8
8
|
headers = base_headers.merge(headers)
|
9
9
|
res = if method == :post || method == :patch || method == :put
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
10
|
+
begin
|
11
|
+
request_body = options[:body].nil? ? '' : options[:body]
|
12
|
+
request_body = request_body.to_json if options[:body].is_a?(Hash)
|
13
|
+
RestClient.send(method, get_url(url), request_body, headers)
|
14
|
+
rescue RestClient::Exception => e
|
15
|
+
e.response
|
16
|
+
end
|
17
|
+
else
|
18
|
+
begin
|
19
|
+
RestClient.send(method, get_url(url), headers)
|
20
|
+
rescue RestClient::Exception => e
|
21
|
+
e.response
|
22
|
+
end
|
23
|
+
end
|
25
24
|
res
|
26
25
|
end
|
27
26
|
end
|
28
|
-
end
|
27
|
+
end
|
data/spec/airborne/base_spec.rb
CHANGED
@@ -10,46 +10,46 @@ describe 'base spec' do
|
|
10
10
|
it 'when request is made headers should be set' do
|
11
11
|
mock_get('simple_get')
|
12
12
|
get '/simple_get'
|
13
|
-
expect(headers).to_not be(nil)
|
13
|
+
expect(headers).to_not be(nil)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should throw an InvalidJsonError when accessing json_body on invalid json' do
|
17
17
|
mock_get('invalid_json')
|
18
18
|
get '/invalid_json'
|
19
|
-
expect(body).to eq(
|
20
|
-
expect{json_body}.to raise_error
|
19
|
+
expect(body).to eq('1234')
|
20
|
+
expect { json_body }.to raise_error
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'when request is made headers should be hash with indifferent access' do
|
24
|
-
mock_get('simple_get',
|
24
|
+
mock_get('simple_get', 'Content-Type' => 'application/json')
|
25
25
|
get '/simple_get'
|
26
26
|
expect(headers).to be_kind_of(Hash)
|
27
27
|
expect(headers[:content_type]).to eq('application/json')
|
28
28
|
expect(headers['content_type']).to eq('application/json')
|
29
|
-
end
|
29
|
+
end
|
30
30
|
|
31
31
|
it 'when request is made body should be set' do
|
32
32
|
mock_get('simple_get')
|
33
33
|
get '/simple_get'
|
34
|
-
expect(body).to_not be(nil)
|
34
|
+
expect(body).to_not be(nil)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'when request is made json body should be symbolized hash' do
|
38
38
|
mock_get('simple_get')
|
39
39
|
get '/simple_get'
|
40
40
|
expect(json_body).to be_kind_of(Hash)
|
41
|
-
expect(json_body.first[0]).to be_kind_of(Symbol)
|
41
|
+
expect(json_body.first[0]).to be_kind_of(Symbol)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should handle a 500 error on get' do
|
45
|
-
mock_get('simple_get', {}, [500,
|
45
|
+
mock_get('simple_get', {}, [500, 'Internal Server Error'])
|
46
46
|
get '/simple_get'
|
47
47
|
expect(json_body).to_not be(nil)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should handle a 500 error on post' do
|
51
|
-
mock_post('simple_post', {}, [500,
|
51
|
+
mock_post('simple_post', {}, [500, 'Internal Server Error'])
|
52
52
|
post '/simple_post', {}
|
53
53
|
expect(json_body).to_not be(nil)
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|