airborne 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/airborne.gemspec +1 -1
- data/lib/airborne/path_matcher.rb +8 -2
- data/lib/airborne/request_expectations.rb +15 -4
- data/spec/airborne/expectations/expect_json_path_spec.rb +7 -0
- data/spec/airborne/expectations/expect_json_types_path_spec.rb +8 -0
- data/spec/airborne/path_spec.rb +21 -0
- data/spec/airborne/post_spec.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9029133bcf1f37e86472d7066159149ccf633423
|
4
|
+
data.tar.gz: 3490ccda6ffafc06a41173f5ba7767c249e589c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efad782993756790afe2fb8cc09503f891f9e4ade418ff70ede1d1811c0d6d4815d64485a13289e7bb55dd51827081376e8c6a5fad90bcd6681bb9c2ddb2808f
|
7
|
+
data.tar.gz: 4f0b6884c93854ea614bc58680c5185a06d7295083ab6d1f61e570284e799ac44b0cd06cbc8c731f4fb959ef0bd746f6b4cb9e446259e32d05033d57e891e685
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[](http://rubygems.org/gems/airborne)
|
8
8
|
[](http://rubygems.org/gems/airborne)
|
9
9
|
|
10
|
-
RSpec driven API testing framework
|
10
|
+
RSpec driven API testing framework
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -360,6 +360,9 @@ end
|
|
360
360
|
|
361
361
|
## Contributors
|
362
362
|
https://github.com/brooklynDev/airborne/graphs/contributors
|
363
|
+
|
364
|
+
Inspired by [frisby.js](https://github.com/vlucas/frisby)
|
365
|
+
|
363
366
|
## License
|
364
367
|
|
365
368
|
The MIT License
|
data/airborne.gemspec
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Airborne
|
2
|
+
class PathError < StandardError; end
|
2
3
|
module PathMatcher
|
3
4
|
|
4
5
|
def get_by_path(path, json, &block)
|
6
|
+
raise PathError, "Ivalid Path, contains '..'" if /\.\./ =~ path
|
5
7
|
type = false
|
6
8
|
parts = path.split('.')
|
7
9
|
parts.each_with_index do |part, index|
|
@@ -14,7 +16,11 @@ module Airborne
|
|
14
16
|
end
|
15
17
|
next
|
16
18
|
end
|
17
|
-
|
19
|
+
begin
|
20
|
+
json = process_json(part, json)
|
21
|
+
rescue
|
22
|
+
raise PathError, "Expected #{json.class}\nto to be an object with property #{part}"
|
23
|
+
end
|
18
24
|
end
|
19
25
|
if type == '*'
|
20
26
|
expect_all(json, &block)
|
@@ -64,7 +70,7 @@ module Airborne
|
|
64
70
|
json.each do |part|
|
65
71
|
begin
|
66
72
|
yield part
|
67
|
-
rescue Exception
|
73
|
+
rescue Exception
|
68
74
|
error_count += 1
|
69
75
|
ensure_match_one(path, item_count, error_count)
|
70
76
|
end
|
@@ -2,6 +2,7 @@ require 'rspec'
|
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module Airborne
|
5
|
+
class ExpectationError < StandardError; end
|
5
6
|
module RequestExpectations
|
6
7
|
include RSpec
|
7
8
|
include PathMatcher
|
@@ -130,7 +131,9 @@ module Airborne
|
|
130
131
|
return expectations.call(hash_or_value) if expectations.class == Proc
|
131
132
|
|
132
133
|
expectations.each do |prop_name, expected_type|
|
133
|
-
value =
|
134
|
+
value = ensure_hash_contains_prop(prop_name, hash_or_value) do
|
135
|
+
expected_type == :date ? convert_to_date(hash_or_value[prop_name]) : hash_or_value[prop_name]
|
136
|
+
end
|
134
137
|
expected_class = expected_type.class
|
135
138
|
value_class = value.class
|
136
139
|
|
@@ -165,7 +168,7 @@ module Airborne
|
|
165
168
|
|
166
169
|
def expect_type(expected_type, value_class, prop_name = nil)
|
167
170
|
insert = prop_name.nil? ? "" : "#{prop_name} to be of type"
|
168
|
-
msg = "Expected #{insert} #{expected_type}\n
|
171
|
+
msg = "Expected #{insert} #{expected_type}\n got #{value_class} instead"
|
169
172
|
expect(@mapper[expected_type].include?(value_class)).to eq(true), msg
|
170
173
|
end
|
171
174
|
|
@@ -174,14 +177,14 @@ module Airborne
|
|
174
177
|
end
|
175
178
|
|
176
179
|
def expect_array(value_class, prop_name, expected_type)
|
177
|
-
expect(value_class).to eq(Array), "Expected #{prop_name}\n to be of type #{expected_type}\n
|
180
|
+
expect(value_class).to eq(Array), "Expected #{prop_name}\n to be of type #{expected_type}\n got #{value_class} instead"
|
178
181
|
end
|
179
182
|
|
180
183
|
def expect_json_impl(expectations, hash)
|
181
184
|
hash = hash.to_s if expectations.class == Regexp
|
182
185
|
return expect(hash).to match(expectations) if is_property?(expectations)
|
183
186
|
expectations.each do |prop_name, expected_value|
|
184
|
-
actual_value = hash[prop_name]
|
187
|
+
actual_value = ensure_hash_contains_prop(prop_name, hash) {hash[prop_name]}
|
185
188
|
expected_class = expected_value.class
|
186
189
|
next expect_json_impl(expected_value, actual_value) if expected_class == Hash
|
187
190
|
next expected_value.call(actual_value) if expected_class == Proc
|
@@ -190,6 +193,14 @@ module Airborne
|
|
190
193
|
end
|
191
194
|
end
|
192
195
|
|
196
|
+
def ensure_hash_contains_prop(prop_name, hash)
|
197
|
+
begin
|
198
|
+
yield
|
199
|
+
rescue
|
200
|
+
raise ExpectationError, "Expected #{hash.class} #{hash}\nto be an object with property #{prop_name}"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
193
204
|
# Convert integers in `old_expectations` to proc
|
194
205
|
#
|
195
206
|
# @param old_expectations [Hash]
|
@@ -99,4 +99,11 @@ describe 'expect_json with path' do
|
|
99
99
|
expect_json('age', 32 )
|
100
100
|
end
|
101
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
|
102
109
|
end
|
@@ -56,4 +56,12 @@ describe 'expect_json_types wih path' do
|
|
56
56
|
expect{expect_json_types('cars.*.owners.*', {name: :string})}.to raise_error
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should raise ExpectationError when expectation expects an object instead of type" do
|
60
|
+
mock_get('array_with_index')
|
61
|
+
get '/array_with_index'
|
62
|
+
expect do
|
63
|
+
expect_json_types('cars.0.make', {make: :string})
|
64
|
+
end.to raise_error(Airborne::ExpectationError, "Expected String Tesla\nto be an object with property make")
|
65
|
+
end
|
66
|
+
|
59
67
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'expect path' do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
mock_get('array_with_index')
|
7
|
+
get '/array_with_index'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise PathError when incorrect path containing .. is used" do
|
11
|
+
expect do
|
12
|
+
expect_json('cars..make', "Tesla")
|
13
|
+
end.to raise_error(Airborne::PathError, "Ivalid Path, contains '..'")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise PathError when trying to call property on an array" do
|
17
|
+
expect do
|
18
|
+
expect_json('cars.make', "Tesla")
|
19
|
+
end.to raise_error(Airborne::PathError, "Expected Array\nto to be an object with property make")
|
20
|
+
end
|
21
|
+
end
|
data/spec/airborne/post_spec.rb
CHANGED
@@ -9,9 +9,9 @@ describe 'post' do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should allow testing on post requests' do
|
12
|
-
|
12
|
+
url = 'http://www.example.com/simple_post'
|
13
13
|
stub_request(:post, url)
|
14
14
|
post '/simple_post', 'hello', {content_type: "text/plain"}
|
15
15
|
expect(WebMock).to have_requested(:post, url).with(:body => "hello", :headers => {'Content-Type' => 'text/plain'})
|
16
16
|
end
|
17
|
-
end
|
17
|
+
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.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Friedman
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- spec/airborne/head_spec.rb
|
143
143
|
- spec/airborne/options_spec.rb
|
144
144
|
- spec/airborne/patch_spec.rb
|
145
|
+
- spec/airborne/path_spec.rb
|
145
146
|
- spec/airborne/post_spec.rb
|
146
147
|
- spec/airborne/put_spec.rb
|
147
148
|
- spec/airborne/rack/rack_sinatra_spec.rb
|
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
182
|
version: '0'
|
182
183
|
requirements: []
|
183
184
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.2.
|
185
|
+
rubygems_version: 2.2.2
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: RSpec driven API testing framework
|