api_matchers 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/api_matchers/core/parser.rb +11 -0
- data/lib/api_matchers/core/rspec_matchers.rb +4 -0
- data/lib/api_matchers/response_body/have_json.rb +27 -0
- data/lib/api_matchers/response_body/have_json_node.rb +2 -6
- data/lib/api_matchers/version.rb +1 -1
- data/lib/api_matchers.rb +2 -0
- data/spec/api_matchers/response_body/have_json_node_spec.rb +51 -51
- data/spec/api_matchers/response_body/have_json_spec.rb +35 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTM2MmZhOGZkNjQ4N2Q1M2ZjMTU0ODhmZjE1ZDBiMjljZTE1YTk4NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGQzMDNiNTQ2YmI2YmU1YWQzZjlkZmZmODk2OTVkZGFmODE1NDc0MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2RhNTE5NzdmYTkwMjE0ZTVlM2EwZmM0ZjY2Y2U3MWQ2ZjA5OWIwMjY2NGVh
|
10
|
+
MmMzNGZhYmE0MzA0OGQ2NjQxYTgyNTJkMDI4YjhmNDJhZmM0NGNmMjAxZjQw
|
11
|
+
ZTRjM2NlNjI4ZDc5ZjYwZTM2ZTY0ZWIwYTQ1MzRiNmNlOGQ2ZDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzIyNmE0NmIwOGQxODRhMmJkN2ZmNmZkMTllOTFjMGJjMzc1MjQ3ZGY4MWZl
|
14
|
+
NWJjMGFiNjA3ZGRmYjZhMzBkOTAxNzgxM2JkOWQyNzUxNmI5NGRkYWRlMDA1
|
15
|
+
NTI4MWEzNDY1MGY0YzI2NzYzMGYxYzEwZDAwNDQyZGUyZTg3NjQ=
|
@@ -46,6 +46,10 @@ module APIMatchers
|
|
46
46
|
::APIMatchers::ResponseBody::HaveXmlNode.new(expected_node: expected_node, setup: ::APIMatchers::Core::Setup)
|
47
47
|
end
|
48
48
|
|
49
|
+
def have_json(expected_json)
|
50
|
+
::APIMatchers::ResponseBody::HaveJson.new(expected_json)
|
51
|
+
end
|
52
|
+
|
49
53
|
def have_node(expected_node)
|
50
54
|
if ::APIMatchers::Core::Setup.have_node_matcher.equal?(:json)
|
51
55
|
have_json_node(expected_node)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module APIMatchers
|
2
|
+
module ResponseBody
|
3
|
+
class HaveJson
|
4
|
+
include APIMatchers::Core::Parser
|
5
|
+
attr_reader :expected_json, :response_body
|
6
|
+
|
7
|
+
def initialize(expected_json)
|
8
|
+
@expected_json = expected_json
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(actual)
|
12
|
+
@response_body = actual
|
13
|
+
|
14
|
+
@expected_json == json
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should
|
18
|
+
"expect to have json: '#{response_body}'. Got: '#{json}'."
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message_for_should_not
|
22
|
+
"expect to NOT have json: '#{response_body}'."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -4,6 +4,8 @@ require 'active_support/core_ext/hash'
|
|
4
4
|
module APIMatchers
|
5
5
|
module ResponseBody
|
6
6
|
class HaveJsonNode < Base
|
7
|
+
include APIMatchers::Core::Parser
|
8
|
+
|
7
9
|
def matches?(actual)
|
8
10
|
@actual = actual
|
9
11
|
|
@@ -19,12 +21,6 @@ module APIMatchers
|
|
19
21
|
false # the key was not found
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
23
|
-
def json
|
24
|
-
JSON.parse(response_body)
|
25
|
-
rescue JSON::ParserError => exception
|
26
|
-
raise ::APIMatchers::InvalidJSON.new("Invalid JSON: '#{response_body}'")
|
27
|
-
end
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
data/lib/api_matchers/version.rb
CHANGED
data/lib/api_matchers.rb
CHANGED
@@ -30,6 +30,7 @@ module APIMatchers
|
|
30
30
|
module ResponseBody
|
31
31
|
autoload :Base, 'api_matchers/response_body/base'
|
32
32
|
autoload :HaveJsonNode, 'api_matchers/response_body/have_json_node'
|
33
|
+
autoload :HaveJson, 'api_matchers/response_body/have_json'
|
33
34
|
autoload :HaveXmlNode, 'api_matchers/response_body/have_xml_node'
|
34
35
|
autoload :HaveNode, 'api_matchers/response_body/have_node'
|
35
36
|
end
|
@@ -38,6 +39,7 @@ module APIMatchers
|
|
38
39
|
#
|
39
40
|
module Core
|
40
41
|
autoload :FindInJSON, 'api_matchers/core/find_in_json'
|
42
|
+
autoload :Parser, 'api_matchers/core/parser'
|
41
43
|
autoload :Setup, 'api_matchers/core/setup'
|
42
44
|
autoload :Exceptions, 'api_matchers/core/exceptions'
|
43
45
|
end
|
@@ -3,62 +3,62 @@ require 'spec_helper'
|
|
3
3
|
describe APIMatchers::ResponseBody::HaveJsonNode do
|
4
4
|
describe "actual.should have_json_node" do
|
5
5
|
context 'expected key and value in top level' do
|
6
|
-
it "
|
6
|
+
it "pass when the expected key exist" do
|
7
7
|
{ :product => 'gateway' }.to_json.should have_json_node(:product)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
10
|
+
it "fail when the expected key does not exist" do
|
11
11
|
expect {
|
12
12
|
{ :product => 'pabx' }.to_json.should have_json_node(:developers)
|
13
13
|
}.to fail_with(%Q{expected to have node called: 'developers'. Got: '{"product":"pabx"}'})
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "pass when the expected key exist with the expected value" do
|
17
17
|
{ :product => 'payment-gateway' }.to_json.should have_json_node(:product).with('payment-gateway')
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "pass when the expected key exist with the expected value (as integer)" do
|
21
21
|
{ :number => 1 }.to_json.should have_json_node(:number).with(1)
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "pass when the expected key exist with the expected value (as boolean, true)" do
|
25
25
|
{ :number => true }.to_json.should have_json_node(:number).with(true)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "pass when the expected key exist with the expected value (as boolean, false)" do
|
29
29
|
{ :number => false }.to_json.should have_json_node(:number).with(false)
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "pass when the expected key exist but the expected value is wrong (as boolean, true)" do
|
33
33
|
{ :number => true }.to_json.should_not have_json_node(:number).with(false)
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "pass when the expected key exist but the expected value is wrong (as boolean, false)" do
|
37
37
|
{ :number => false }.to_json.should_not have_json_node(:number).with(true)
|
38
38
|
end
|
39
39
|
|
40
|
-
it "
|
40
|
+
it "pass when the expected key exists with the expected value (as DateTime)" do
|
41
41
|
now = DateTime.now
|
42
42
|
{ :date => now }.to_json.should have_json_node(:date).with(now)
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
45
|
+
it "pass when the expected key exists with the expected value (as Date)" do
|
46
46
|
now = Date.today
|
47
47
|
{ :date => now }.to_json.should have_json_node(:date).with(now)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "
|
50
|
+
it "pass when the expected key exists with the expected value (as Time)" do
|
51
51
|
now = Time.now
|
52
52
|
{ :time => now }.to_json.should have_json_node(:time).with(now)
|
53
53
|
end
|
54
54
|
|
55
|
-
it "
|
55
|
+
it "fail when the expected key exist but the expected value don't exist" do
|
56
56
|
expect {
|
57
57
|
{ :product => 'payment-gateway' }.to_json.should have_json_node(:product).with('email-marketing')
|
58
58
|
}.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '{"product":"payment-gateway"}'})
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "not parse the matcher for json when you pass a xml" do
|
62
62
|
expect {
|
63
63
|
"<product><name>webdesk</name></product>".should have_json_node(:name).with('webdesk')
|
64
64
|
}.to raise_error(APIMatchers::InvalidJSON, "Invalid JSON: '<product><name>webdesk</name></product>'")
|
@@ -66,15 +66,15 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
context 'expected key and nil value' do
|
69
|
-
it "
|
69
|
+
it "pass when the expected key exists" do
|
70
70
|
{ :product => nil }.to_json.should have_json_node(:product)
|
71
71
|
end
|
72
72
|
|
73
|
-
it "
|
73
|
+
it "pass when the expected key exists and the expected value is nil" do
|
74
74
|
{ :product => nil }.to_json.should have_json_node(:product).with( nil )
|
75
75
|
end
|
76
76
|
|
77
|
-
it "
|
77
|
+
it "fail when the expected key exist but the expected value don't exist" do
|
78
78
|
expect {
|
79
79
|
{ :product => nil }.to_json.should have_json_node(:product).with('email-marketing')
|
80
80
|
}.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '{"product":null}'})
|
@@ -83,89 +83,89 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
83
83
|
|
84
84
|
context 'expected key and value in more deep in the JSON' do
|
85
85
|
context '.to_json used' do
|
86
|
-
it "
|
86
|
+
it "pass when the expected key exist" do
|
87
87
|
{ :transaction => { :id => 150 } }.to_json.should have_json_node(:id)
|
88
88
|
end
|
89
89
|
|
90
|
-
it "
|
90
|
+
it "pass when the expected key and expected value exist" do
|
91
91
|
{ :transaction => { :error => { :code => '999' } } }.to_json.should have_json_node(:code).with('999')
|
92
92
|
end
|
93
93
|
|
94
|
-
it "
|
94
|
+
it "pass when the expected key and expected value exist in very deep" do
|
95
95
|
{ :first=>"A", :second=>nil, :third=>{ :stuff => { :first_stuff=>{ :color=>"green", :size=>"small", :shape=>"circle", :uid=>"first_stuff"}, :second_stuff=>{ :color=>"blue", :size=>"large", :shape=>"square", :uid=>"second_stuff"}}, :junk=>[{"name"=>"junk_one", :uid=>"junk_one", :stuff_uid=>"first_stuff"}, { :name=>"junk_two", :uid=>"junk_two", :stuff_uid=>"second_stuff"}]}}.to_json.should have_json_node( :junk )
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
98
|
+
it "pass when the expected key and expected value exist in very deep" do
|
99
99
|
{ :first=>"A", :second=>nil, :third=>{ :stuff => { :first_stuff=>{ :color=>"green", :size=>"small", :shape=>"circle", :uid=>"first_stuff"}, :second_stuff=>{ :color=>"blue", :size=>"large", :shape=>"square", :uid=>"second_stuff"}}, :junk=>[{"name"=>"junk_one", :uid=>"junk_one", :stuff_uid=>"first_stuff"}, { :name=>"junk_two", :uid=>"junk_two", :stuff_uid=>"second_stuff"}]}}.to_json.should have_json_node( :name ).with( "junk_two" )
|
100
100
|
end
|
101
101
|
|
102
|
-
it "
|
102
|
+
it "fail when the expected key does not exist" do
|
103
103
|
expect {
|
104
104
|
{ :transaction => { :id => 150, :error => {} } }.to_json.should have_json_node(:code)
|
105
105
|
}.to fail_with(%Q{expected to have node called: 'code'. Got: '{"transaction":{"id":150,"error":{}}}'})
|
106
106
|
end
|
107
107
|
|
108
|
-
it "
|
108
|
+
it "fail when the expected key exist but don't exist the expected value" do
|
109
109
|
expect {
|
110
110
|
{ :transaction => { :id => 150, :error => { :code => '999' } } }.to_json.should have_json_node(:code).with('001')
|
111
111
|
}.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
|
112
112
|
end
|
113
113
|
end
|
114
114
|
context 'json string used' do
|
115
|
-
it "
|
115
|
+
it "pass when the expected key exist" do
|
116
116
|
'{ "transaction": {"id": 150 } }'.should have_json_node(:id)
|
117
117
|
end
|
118
118
|
|
119
|
-
it "
|
119
|
+
it "pass when the expected key and expected value exist" do
|
120
120
|
'{ "transaction": {"error": { "code": "999" } } }'.should have_json_node(:code).with('999')
|
121
121
|
end
|
122
122
|
|
123
|
-
it "
|
123
|
+
it "pass when the expected key exist with the expected value (as integer)" do
|
124
124
|
'{"number":1 }'.should have_json_node(:number).with(1)
|
125
125
|
end
|
126
126
|
|
127
|
-
it "
|
127
|
+
it "pass when the expected key exist with the expected value (as boolean)" do
|
128
128
|
'{"boolean":true}'.should have_json_node(:boolean).with(true)
|
129
129
|
end
|
130
130
|
|
131
|
-
it "
|
131
|
+
it "pass when the expected key exists with the expected value (as DateTime)" do
|
132
132
|
now = DateTime.parse( "2012-09-18T15:42:12-07:00" )
|
133
133
|
'{"date": "2012-09-18T15:42:12-07:00"}'.should have_json_node(:date).with(now)
|
134
134
|
end
|
135
135
|
|
136
|
-
it "
|
136
|
+
it "pass when the expected key exists with the expected value (as Date)" do
|
137
137
|
now = Date.parse( "2012-09-18" )
|
138
138
|
'{"date": "2012-09-18"}'.should have_json_node(:date).with(now)
|
139
139
|
end
|
140
140
|
|
141
|
-
it "
|
141
|
+
it "pass when the expected key exists with the expected value (as Time)" do
|
142
142
|
now = Time.parse("2012-09-18T15:42:12Z")
|
143
143
|
'{"time": "2012-09-18T15:42:12+00:00"}'.should have_json_node(:time).with(now)
|
144
144
|
end
|
145
145
|
|
146
|
-
it "
|
146
|
+
it "pass when the expected key exist with the expected value (as boolean) in a multi node" do
|
147
147
|
'{"uid":"123456","boolean":true}'.should have_json_node(:boolean).with(true)
|
148
148
|
end
|
149
149
|
|
150
|
-
it "
|
150
|
+
it "pass when the expected key and expected value exist in very deep" do
|
151
151
|
'{"first":"A","second":null,"third":{"stuff":{"first_stuff":{"color":"green","size":"small","shape":"circle","uid":"first_stuff"},"second_stuff":{"color":"blue","size":"large","shape":"square","uid":"second_stuff"}},"junk":[{"name":"junk_one","uid":"junk_one","stuff_uid":"first_stuff"},{"name":"junk_two","uid":"junk_two","stuff_uid":"second_stuff"}]}}'.should have_json_node( :junk )
|
152
152
|
end
|
153
153
|
|
154
|
-
it "
|
154
|
+
it "pass when the expected key and expected value exist in very deep" do
|
155
155
|
'{"first":"A","second":null,"third":{"stuff":{"first_stuff":{"color":"green","size":"small","shape":"circle","uid":"first_stuff"},"second_stuff":{"color":"blue","size":"large","shape":"square","uid":"second_stuff"}},"junk":[{"name":"junk_one","uid":"junk_one","stuff_uid":"first_stuff"},{"name":"junk_two","uid":"junk_two","stuff_uid":"second_stuff"}]}}'.should have_json_node( :name ).with( "junk_two" )
|
156
156
|
end
|
157
157
|
|
158
|
-
it "
|
158
|
+
it "pass when the expected key and including text exist" do
|
159
159
|
'{"Key":"A=123456-abcdef-09876-ghijkl; path=/; expires=Sun, 05-Sep-2032 05:50:39 GMT\nB=ABCDEF123456; path=/; expires=Sun, 05-Sep-2032 05:50:39 GMT", "Content-Type":"application/json; charset=utf-8"}'.should have_json_node( "Key" ).including_text( "123456-abcdef-09876-ghijkl" )
|
160
160
|
end
|
161
161
|
|
162
|
-
it "
|
162
|
+
it "fail when the expected key does not exist" do
|
163
163
|
expect {
|
164
164
|
'{"transaction":{"id":150,"error":{}}}'.should have_json_node(:code)
|
165
165
|
}.to fail_with(%Q{expected to have node called: 'code'. Got: '{"transaction":{"id":150,"error":{}}}'})
|
166
166
|
end
|
167
167
|
|
168
|
-
it "
|
168
|
+
it "fail when the expected key exist but don't exist the expected value" do
|
169
169
|
expect {
|
170
170
|
'{"transaction":{"id":150,"error":{"code":"999"}}}'.should have_json_node(:code).with('001')
|
171
171
|
}.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
|
@@ -174,11 +174,11 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
context "including_text" do
|
177
|
-
it "
|
177
|
+
it "pass when the expected is included in the actual" do
|
178
178
|
{ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should have_json_node(:message).including_text("Transaction error")
|
179
179
|
end
|
180
180
|
|
181
|
-
it "
|
181
|
+
it "fail when the expected is not included in the actual" do
|
182
182
|
expect {
|
183
183
|
{ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should have_json_node(:message).including_text("Fox on the run")
|
184
184
|
}.to fail_with(%Q{expected to have node called: 'message' including text: 'Fox on the run'. Got: '{"transaction":{"error":{"message":"Transaction error: Name can't be blank"}}}'})
|
@@ -187,36 +187,36 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
187
187
|
end
|
188
188
|
|
189
189
|
describe "actual.should_not have_json_node" do
|
190
|
-
it "
|
190
|
+
it "pass when don't have the expected node in root level" do
|
191
191
|
{ :product => 'gateway' }.to_json.should_not have_json_node(:status)
|
192
192
|
end
|
193
193
|
|
194
|
-
it "
|
194
|
+
it "pass when don't have the expected node in any level" do
|
195
195
|
{ :transaction => { :id => 12, :status => 'paid' } }.to_json.should_not have_json_node(:error)
|
196
196
|
end
|
197
197
|
|
198
|
-
it "
|
198
|
+
it "fail when the expected key exist" do
|
199
199
|
expect {
|
200
200
|
{ :status => 'paid' }.to_json.should_not have_json_node(:status)
|
201
201
|
}.to fail_with(%Q{expected to NOT have node called: 'status'. Got: '{"status":"paid"}'})
|
202
202
|
end
|
203
203
|
|
204
|
-
it "
|
204
|
+
it "pass when have the expected key but have a different value" do
|
205
205
|
{ :status => 'paid' }.to_json.should_not have_json_node(:status).with('not_authorized')
|
206
206
|
end
|
207
207
|
|
208
|
-
it "
|
208
|
+
it "fail when have the expected key and have the expected value" do
|
209
209
|
expect {
|
210
210
|
{ :status => 'paid' }.to_json.should_not have_json_node(:status).with('paid')
|
211
211
|
}.to fail_with(%Q{expected to NOT have node called: 'status' with value: 'paid'. Got: '{"status":"paid"}'})
|
212
212
|
end
|
213
213
|
|
214
214
|
context "including_text" do
|
215
|
-
it "
|
215
|
+
it "pass when the expected is NOT included in the actual" do
|
216
216
|
{ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should_not have_json_node(:message).including_text("Love gun")
|
217
217
|
end
|
218
218
|
|
219
|
-
it "
|
219
|
+
it "fail when the expected is included in the actual" do
|
220
220
|
expect {
|
221
221
|
{ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should_not have_json_node(:message).including_text("Transaction error")
|
222
222
|
}.to fail_with(%Q{expected to NOT have node called: 'message' including text: 'Transaction error'. Got: '{"transaction":{"error":{"message":"Transaction error: Name can't be blank"}}}'})
|
@@ -225,11 +225,11 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
describe "some assumptions" do
|
228
|
-
it "
|
228
|
+
it "pass when have the json node name" do
|
229
229
|
'{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:transaction)
|
230
230
|
end
|
231
231
|
|
232
|
-
it "
|
232
|
+
it "pass when have json node with integer value" do
|
233
233
|
'{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:id).with(54)
|
234
234
|
end
|
235
235
|
|
@@ -237,15 +237,15 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
237
237
|
'{"error": "Transaction error: Name cant be blank"}'.should have_json_node(:error).including_text("Transaction error")
|
238
238
|
end
|
239
239
|
|
240
|
-
it "
|
240
|
+
it "pass have json node with boolean value" do
|
241
241
|
'{"creditcard": true}'.should have_json_node(:creditcard).with(true)
|
242
242
|
end
|
243
243
|
|
244
|
-
it "
|
244
|
+
it "pass have json node with string" do
|
245
245
|
'{ "error": "not_authorized", "transaction": { "id": "55" } }'.should have_node(:error).with('not_authorized')
|
246
246
|
end
|
247
247
|
|
248
|
-
it "
|
248
|
+
it "pass have json node with integer" do
|
249
249
|
'{"parcels": 1 }'.should have_node(:parcels).with(1)
|
250
250
|
end
|
251
251
|
end
|
@@ -259,12 +259,12 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
259
259
|
APIMatchers.setup { |config| config.response_body_method = nil }
|
260
260
|
end
|
261
261
|
|
262
|
-
it "
|
262
|
+
it "pass if the actual.http_status is equal to 400" do
|
263
263
|
response = OpenStruct.new(:response_body => { :foo => :bar }.to_json)
|
264
264
|
response.should have_json_node(:foo).with('bar')
|
265
265
|
end
|
266
266
|
|
267
|
-
it "
|
267
|
+
it "fail if the actual.http_status is not equal to 400" do
|
268
268
|
response = OpenStruct.new(:response_body => { :baz => :foo}.to_json)
|
269
269
|
expect { response.should have_json_node(:bar) }.to fail_with(%Q{expected to have node called: 'bar'. Got: '{"baz":"foo"}'})
|
270
270
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APIMatchers::ResponseBody::HaveJson do
|
4
|
+
describe "actual.should have_json" do
|
5
|
+
context 'when pass' do
|
6
|
+
it 'equal json' do
|
7
|
+
['Petshop', 'Dogs'].to_json.should have_json(['Petshop', 'Dogs'])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when fails' do
|
12
|
+
it 'different json' do
|
13
|
+
expect {
|
14
|
+
['Petshop', 'Cats'].to_json.should have_json(['Petshop', 'Dogs'])
|
15
|
+
}.to fail_with(%Q{expect to have json: '["Petshop","Cats"]'. Got: '["Petshop", "Cats"]'.})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "actual.should_not have_json" do
|
21
|
+
context 'when pass' do
|
22
|
+
it 'different json' do
|
23
|
+
['Petshop', 'Cats'].to_json.should_not have_json(['Petshop', 'Dogs'])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when fails' do
|
28
|
+
it 'equal json' do
|
29
|
+
expect {
|
30
|
+
['Petshop', 'Cats'].to_json.should_not have_json(['Petshop', 'Cats'])
|
31
|
+
}.to fail_with(%Q{expect to NOT have json: '["Petshop","Cats"]'.})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas D'Stefano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/api_matchers.rb
|
72
72
|
- lib/api_matchers/core/exceptions.rb
|
73
73
|
- lib/api_matchers/core/find_in_json.rb
|
74
|
+
- lib/api_matchers/core/parser.rb
|
74
75
|
- lib/api_matchers/core/rspec_matchers.rb
|
75
76
|
- lib/api_matchers/core/setup.rb
|
76
77
|
- lib/api_matchers/headers/base.rb
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- lib/api_matchers/http_status_code/be_unauthorized.rb
|
85
86
|
- lib/api_matchers/http_status_code/create_resource.rb
|
86
87
|
- lib/api_matchers/response_body/base.rb
|
88
|
+
- lib/api_matchers/response_body/have_json.rb
|
87
89
|
- lib/api_matchers/response_body/have_json_node.rb
|
88
90
|
- lib/api_matchers/response_body/have_node.rb
|
89
91
|
- lib/api_matchers/response_body/have_xml_node.rb
|
@@ -102,6 +104,7 @@ files:
|
|
102
104
|
- spec/api_matchers/http_status_code/create_resource_spec.rb
|
103
105
|
- spec/api_matchers/response_body/base_spec.rb
|
104
106
|
- spec/api_matchers/response_body/have_json_node_spec.rb
|
107
|
+
- spec/api_matchers/response_body/have_json_spec.rb
|
105
108
|
- spec/api_matchers/response_body/have_node_spec.rb
|
106
109
|
- spec/api_matchers/response_body/have_xml_node_spec.rb
|
107
110
|
- spec/spec_helper.rb
|
@@ -143,6 +146,7 @@ test_files:
|
|
143
146
|
- spec/api_matchers/http_status_code/create_resource_spec.rb
|
144
147
|
- spec/api_matchers/response_body/base_spec.rb
|
145
148
|
- spec/api_matchers/response_body/have_json_node_spec.rb
|
149
|
+
- spec/api_matchers/response_body/have_json_spec.rb
|
146
150
|
- spec/api_matchers/response_body/have_node_spec.rb
|
147
151
|
- spec/api_matchers/response_body/have_xml_node_spec.rb
|
148
152
|
- spec/spec_helper.rb
|