airborne 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/airborne.gemspec +1 -1
- data/lib/airborne/request_expectations.rb +12 -3
- data/spec/airborne/expectations/expect_json_options_spec.rb +59 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6dbdb4e4fb42256d136b4fc15bc52604ec7ec55
|
4
|
+
data.tar.gz: 5babb01a3f583438d337cd63a678d6ddfb522cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b531a941356a2861b90aa2abbcc04ce2aa68191dabe6d748275fe4ddb424b350b7ea56dd6cb625d0b3bbe93258f3fea1e20318c3e6ab2769120b0e6699f498ff
|
7
|
+
data.tar.gz: f702beedc737affede6c4b51531b2ed097b2415afba2c3cc555b4bad43cd11d348dacf71fb7c70247c5eb6fcd0c0a2367a075eaa22a133aa78d855f1c8ad3d13
|
data/airborne.gemspec
CHANGED
@@ -85,7 +85,7 @@ module Airborne
|
|
85
85
|
keys = expected.keys & actual.keys if match_none?
|
86
86
|
|
87
87
|
keys.flatten.uniq.each do |prop|
|
88
|
-
expected_value =
|
88
|
+
expected_value = extract_expected_value(expected, prop)
|
89
89
|
actual_value = extract_actual(actual, prop)
|
90
90
|
|
91
91
|
next expect_json_impl(expected_value, actual_value) if hash?(expected_value)
|
@@ -113,7 +113,7 @@ module Airborne
|
|
113
113
|
keys = expected.keys & actual.keys if match_none?
|
114
114
|
|
115
115
|
keys.flatten.uniq.each do |prop|
|
116
|
-
type =
|
116
|
+
type = extract_expected_type(expected, prop)
|
117
117
|
value = extract_actual(actual, prop)
|
118
118
|
value = convert_to_date(value) if type == :date
|
119
119
|
|
@@ -140,7 +140,16 @@ module Airborne
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
def
|
143
|
+
def extract_expected_value(expected, prop)
|
144
|
+
begin
|
145
|
+
raise unless expected.keys.include?(prop)
|
146
|
+
expected[prop]
|
147
|
+
rescue
|
148
|
+
raise ExpectationError, "Expectation is expected to contain property: #{prop}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def extract_expected_type(expected, prop)
|
144
153
|
begin
|
145
154
|
type = expected[prop]
|
146
155
|
type.nil? ? raise : type
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'expect_json options' do
|
4
|
+
describe 'match_expected', match_expected: true, match_actual: false do
|
5
|
+
it 'should require all expected properties' do
|
6
|
+
mock_get 'simple_get'
|
7
|
+
get '/simple_get'
|
8
|
+
expect{ expect_json(name: 'Alex', other: 'other') }.to raise_error(ExpectationNotMetError)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should not require the actual properties' do
|
12
|
+
mock_get 'simple_get'
|
13
|
+
get '/simple_get'
|
14
|
+
expect_json(name: 'Alex')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'match_actual', match_expected: false, match_actual: true do
|
19
|
+
it 'should require all actual properties' do
|
20
|
+
mock_get 'simple_get'
|
21
|
+
get '/simple_get'
|
22
|
+
expect{ expect_json(name: 'Alex') }.to raise_error(ExpectationError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should not require the expected properties' do
|
26
|
+
mock_get 'simple_get'
|
27
|
+
get '/simple_get'
|
28
|
+
expect_json(name: 'Alex', age: 32, address: nil, other: 'other')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'match_both', match_expected: true, match_actual: true do
|
33
|
+
it 'should require all actual properties' do
|
34
|
+
mock_get 'simple_get'
|
35
|
+
get '/simple_get'
|
36
|
+
expect{ expect_json(name: 'Alex') }.to raise_error(ExpectationError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should require all expected properties' do
|
40
|
+
mock_get 'simple_get'
|
41
|
+
get '/simple_get'
|
42
|
+
expect{ expect_json(name: 'Alex', other: 'other') }.to raise_error(ExpectationNotMetError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'match_none', match_expected: false, match_actual: false do
|
47
|
+
it 'should not require the actual properties' do
|
48
|
+
mock_get 'simple_get'
|
49
|
+
get '/simple_get'
|
50
|
+
expect_json(name: 'Alex')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not require the expected properties' do
|
54
|
+
mock_get 'simple_get'
|
55
|
+
get '/simple_get'
|
56
|
+
expect_json(name: 'Alex', age: 32, address: nil, other: 'other')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Friedman
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- spec/airborne/expectations/expect_json_keys_path_spec.rb
|
130
130
|
- spec/airborne/expectations/expect_json_keys_spec.rb
|
131
131
|
- spec/airborne/expectations/expect_json_lambda_spec.rb
|
132
|
+
- spec/airborne/expectations/expect_json_options_spec.rb
|
132
133
|
- spec/airborne/expectations/expect_json_path_spec.rb
|
133
134
|
- spec/airborne/expectations/expect_json_regex_spec.rb
|
134
135
|
- spec/airborne/expectations/expect_json_sizes_spec.rb
|