api_matchers 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/History.markdown +5 -0
- data/README.markdown +89 -6
- data/lib/api_matchers.rb +1 -0
- data/lib/api_matchers/core/exceptions.rb +8 -0
- data/lib/api_matchers/core/find_in_json.rb +27 -4
- data/lib/api_matchers/response_body/have_json_node.rb +17 -7
- data/lib/api_matchers/version.rb +1 -1
- data/spec/api_matchers/core/find_in_json_spec.rb +2 -2
- data/spec/api_matchers/response_body/have_json_node_spec.rb +137 -16
- data/spec/api_matchers/response_body/have_xml_node_spec.rb +1 -1
- metadata +25 -9
data/.gitignore
CHANGED
data/History.markdown
CHANGED
data/README.markdown
CHANGED
@@ -26,94 +26,165 @@ Collection of RSpec matchers for create your API.
|
|
26
26
|
|
27
27
|
To include all this matchers you need to include the APIMatchers::RSpecMatchers module:
|
28
28
|
|
29
|
+
```ruby
|
29
30
|
RSpec.configure do |config|
|
30
31
|
config.include APIMatchers::RSpecMatchers
|
31
32
|
end
|
33
|
+
```
|
32
34
|
|
33
35
|
### Have Node Matcher
|
34
36
|
|
35
37
|
The have_node matcher parse the actual and see if have the expcted node with the expected value.
|
36
38
|
**The default that have_node will parse is JSON.**
|
37
39
|
|
40
|
+
You can verify if node exists:
|
41
|
+
|
42
|
+
```ruby
|
38
43
|
"{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:transaction)
|
44
|
+
```
|
45
|
+
|
46
|
+
Or if node exist with a value:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
"{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:id).with(54)
|
50
|
+
```
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
"{ 'error': 'not_authorized', 'transaction': { 'id': '55' } }".should have_node(:error).with('not_authorized')
|
54
|
+
```
|
39
55
|
|
40
|
-
|
56
|
+
```ruby
|
57
|
+
'{"parcels":1 }'.should have_node(:parcels).with(1)
|
58
|
+
```
|
41
59
|
|
42
|
-
|
60
|
+
To see the json node and see if include a text, you can do this:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
'{"error": "Transaction error: Name cant be blank"}'.should have_node(:error).including_text("Transaction error")
|
64
|
+
```
|
65
|
+
|
66
|
+
You can verify boolean values too:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
'{"creditcard":true}'.should have_node(:creditcard).with(true)
|
70
|
+
```
|
43
71
|
|
44
72
|
### HAVE NODE Matcher Configuration
|
45
73
|
|
46
74
|
You can configure if you want xml(**JSON is the default**):
|
47
75
|
|
76
|
+
```ruby
|
48
77
|
APIMatchers.setup do |config|
|
49
78
|
config.content_type = :xml
|
50
79
|
end
|
80
|
+
```ruby
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
'<transaction><id>200</id><status>paid</status></transaction>'.should have_node(:status)
|
84
|
+
```
|
51
85
|
|
52
|
-
|
86
|
+
Using the with method:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
'<transaction><id>200</id><status>paid</status></transaction>'.should have_node(:status).with('paid')
|
90
|
+
```
|
91
|
+
|
92
|
+
Or you can use the **have_xml_node** matcher:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
"<error>Transaction error: Name can't be blank</error>".should have_xml_node(:error).with("Transaction error: Name can't be blank")
|
96
|
+
```
|
97
|
+
|
98
|
+
To see the xml node and see if include a text, you can do this:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
"<error>Transaction error: Name can't be blank</error>".should have_xml_node(:error).including_text("Transaction error")
|
102
|
+
```
|
53
103
|
|
54
104
|
**If you work with xml and json in the same API, I recommend that you check the have_json_node and have_xml_node matchers.**
|
55
105
|
|
56
106
|
You can configure the name of the method for example:
|
57
107
|
|
108
|
+
```ruby
|
58
109
|
## Instead of this
|
59
110
|
response.body.should have_node(:foo)
|
111
|
+
```
|
60
112
|
|
113
|
+
```ruby
|
61
114
|
## YOU can do this
|
62
115
|
APIMatchers.setup do |config|
|
63
116
|
config.body_method = :body
|
64
117
|
end
|
118
|
+
```
|
65
119
|
|
66
|
-
Then you can use without call the **#body** method:
|
120
|
+
Then you can use *without* call the **#body** method:
|
67
121
|
|
122
|
+
```ruby
|
68
123
|
response.should have_node(:foo).with('bar')
|
124
|
+
```
|
69
125
|
|
70
126
|
### Have JSON Node Matcher
|
71
127
|
|
128
|
+
```ruby
|
72
129
|
"{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_json_node(:id).with(54)
|
130
|
+
```
|
73
131
|
|
74
132
|
### Have XML Node Matcher
|
75
133
|
|
134
|
+
```ruby
|
76
135
|
"<product><name>gateway</name></product>".should have_xml_node(:name).with('gateway')
|
77
|
-
|
136
|
+
```
|
78
137
|
|
79
138
|
### Create Resource Matcher
|
80
139
|
|
81
140
|
This matchers see the HTTP STATUS CODE is equal to 201.
|
82
141
|
|
142
|
+
```ruby
|
83
143
|
response.status.should create_resource
|
144
|
+
```
|
84
145
|
|
85
146
|
### BAD REQUEST Matcher
|
86
147
|
|
87
148
|
This BAD REQUEST is a matcher that see if the HTTP STATUS code is equal to 400.
|
88
149
|
|
150
|
+
```ruby
|
89
151
|
response.status.should be_a_bad_request
|
90
152
|
response.status.should be_bad_request
|
153
|
+
```
|
91
154
|
|
92
155
|
### UNAUTHORIZED Matcher
|
93
156
|
|
94
157
|
This UNAUTHORIZED is a matcher that see if the HTTP STATUS code is equal to 401.
|
95
158
|
|
159
|
+
```ruby
|
96
160
|
response.status.should be_unauthorized
|
97
161
|
response.body.should have_node(:message).with('Invalid Credentials')
|
162
|
+
```
|
98
163
|
|
99
164
|
### INTERNAL SERVER ERROR Matcher
|
100
165
|
|
101
166
|
This INTERNAL SERVER Error is a matcher that see if the HTTP STATUS code is equal to 500.
|
102
167
|
|
168
|
+
```ruby
|
103
169
|
response.status.should be_internal_server_error
|
104
170
|
response.body.should have_node(:message).with('An Internal Error Occurs in our precious app. :S')
|
171
|
+
```
|
105
172
|
|
106
173
|
### HTTP STATUS CODE Configuration
|
107
174
|
|
108
175
|
You can configure the name method to call the http status code:
|
109
176
|
|
177
|
+
```ruby
|
110
178
|
APIMatchers.setup do |config|
|
111
179
|
config.http_status_method = :status
|
112
180
|
end
|
181
|
+
```
|
113
182
|
|
114
183
|
Then you can use without call the **#status** method:
|
115
184
|
|
185
|
+
```ruby
|
116
186
|
response.should create_resource
|
187
|
+
```
|
117
188
|
|
118
189
|
This configurations affects this matchers:
|
119
190
|
|
@@ -126,28 +197,40 @@ This configurations affects this matchers:
|
|
126
197
|
|
127
198
|
This is a matcher that see if the content type is xml:
|
128
199
|
|
200
|
+
```ruby
|
129
201
|
response.headers['Content-Type'].should be_in_xml
|
202
|
+
```
|
130
203
|
|
131
204
|
### Be in JSON Matcher
|
132
205
|
|
133
206
|
This is a matcher that see if the content type is in JSON:
|
134
207
|
|
208
|
+
```ruby
|
135
209
|
response.headers['Content-Type'].should be_in_json
|
210
|
+
```
|
136
211
|
|
137
212
|
### Headers Configuration
|
138
213
|
|
139
214
|
You can configure the name method to call the headers and content type:
|
140
215
|
|
216
|
+
```ruby
|
141
217
|
APIMatchers.setup do |config|
|
142
218
|
config.header_method = :headers
|
143
219
|
config.header_content_type_key = 'Content-Type'
|
144
220
|
end
|
221
|
+
```
|
145
222
|
|
146
223
|
Then you can use without call the **#headers** calling the **#['Content-Type']** method:
|
147
224
|
|
225
|
+
```ruby
|
148
226
|
response.should be_in_json
|
149
227
|
response.should be_in_xml
|
228
|
+
```
|
150
229
|
|
151
230
|
### Acknowlegments
|
152
231
|
|
153
|
-
* Special thanks to Daniel Konishi to contribute in the product that I extracted the matchers to this gem.
|
232
|
+
* Special thanks to Daniel Konishi to contribute in the product that I extracted the matchers to this gem.
|
233
|
+
|
234
|
+
### Contributors
|
235
|
+
|
236
|
+
* Stephen Orens
|
data/lib/api_matchers.rb
CHANGED
@@ -9,16 +9,39 @@ module APIMatchers
|
|
9
9
|
|
10
10
|
def find(options={})
|
11
11
|
expected_key = options.fetch(:node).to_s
|
12
|
+
expected_value = options[:value]
|
12
13
|
|
13
14
|
@json.each do |key, value|
|
14
15
|
if key == expected_key
|
15
|
-
|
16
|
+
unless expected_value.nil?
|
17
|
+
if expected_value.is_a? DateTime or expected_value.is_a? Date
|
18
|
+
expected_value = expected_value.to_s
|
19
|
+
elsif expected_value.is_a? Time
|
20
|
+
expected_value = expected_value.to_datetime.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
return value if value == expected_value or expected_value.nil?
|
25
|
+
end
|
26
|
+
# do we have more to recurse through?
|
27
|
+
keep_going = nil
|
28
|
+
if value.is_a? Hash or value.is_a? Array
|
29
|
+
keep_going = value # hash or array, keep going
|
30
|
+
elsif value.nil? and key.is_a? Hash
|
31
|
+
keep_going = key # the array was passed in and now in the key, keep going
|
16
32
|
end
|
17
|
-
|
18
|
-
|
33
|
+
|
34
|
+
if keep_going
|
35
|
+
begin
|
36
|
+
# ignore nodes where the key doesn't match
|
37
|
+
return FindInJSON.new(keep_going).find(node: expected_key, value: expected_value)
|
38
|
+
rescue ::APIMatchers::Core::Exceptions::KeyNotFound
|
39
|
+
end
|
19
40
|
end
|
41
|
+
|
20
42
|
end
|
21
|
-
|
43
|
+
# we did not find the requested key
|
44
|
+
raise ::APIMatchers::Core::Exceptions::KeyNotFound.new("key was not found")
|
22
45
|
end
|
23
46
|
end
|
24
47
|
end
|
@@ -12,14 +12,24 @@ module APIMatchers
|
|
12
12
|
{}
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
begin
|
16
|
+
options = {}
|
17
|
+
options[:node] = @expected_node.to_s
|
18
|
+
unless @with_value.nil?
|
19
|
+
options[:value] = @with_value
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
node = Core::FindInJSON.new(json).find( options )
|
23
|
+
|
24
|
+
if @expected_including_text
|
25
|
+
node.to_s.include?(@expected_including_text)
|
26
|
+
else
|
27
|
+
# the node is present
|
28
|
+
true
|
29
|
+
end
|
30
|
+
rescue ::APIMatchers::Core::Exceptions::KeyNotFound
|
31
|
+
# the key was not found
|
32
|
+
false
|
23
33
|
end
|
24
34
|
end
|
25
35
|
end
|
data/lib/api_matchers/version.rb
CHANGED
@@ -15,11 +15,11 @@ module APIMatchers::Core
|
|
15
15
|
|
16
16
|
context 'when node do not exists' do
|
17
17
|
it "should return nil if don't find the expected node" do
|
18
|
-
FindInJSON.new('product' => 'pabx').find(node: 'developers').should
|
18
|
+
expect{ FindInJSON.new('product' => 'pabx').find(node: 'developers').should raise_error( ::APIMatchers::Core::Exceptions::KeyNotFound ) }
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return nil if don't find the expected node in the deep JSON" do
|
22
|
-
FindInJSON.new('transaction' => { 'id' => 150, 'error' => {} }).find(node: 'code').should
|
22
|
+
expect{ FindInJSON.new('transaction' => { 'id' => 150, 'error' => {} }).find(node: 'code').should raise_error( ::APIMatchers::Core::Exceptions::KeyNotFound ) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -9,7 +9,7 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
9
9
|
|
10
10
|
it "should 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
|
|
@@ -17,9 +17,44 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
17
17
|
{ :product => 'payment-gateway' }.to_json.should have_json_node(:product).with('payment-gateway')
|
18
18
|
end
|
19
19
|
|
20
|
+
it "should pass when the expected key exist with the expected value (as integer)" do
|
21
|
+
{ :number => 1 }.to_json.should have_json_node(:number).with(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should pass when the expected key exist with the expected value (as boolean, true)" do
|
25
|
+
{ :number => true }.to_json.should have_json_node(:number).with(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should pass when the expected key exist with the expected value (as boolean, false)" do
|
29
|
+
{ :number => false }.to_json.should have_json_node(:number).with(false)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should pass when the expected key exist but the expected value is wrong (as boolean, true)" do
|
33
|
+
{ :number => true }.to_json.should_not have_json_node(:number).with(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should pass when the expected key exist but the expected value is wrong (as boolean, false)" do
|
37
|
+
{ :number => false }.to_json.should_not have_json_node(:number).with(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should pass when the expected key exists with the expected value (as DateTime)" do
|
41
|
+
now = DateTime.now
|
42
|
+
{ :date => now }.to_json.should have_json_node(:date).with(now)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should pass when the expected key exists with the expected value (as Date)" do
|
46
|
+
now = Date.today
|
47
|
+
{ :date => now }.to_json.should have_json_node(:date).with(now)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should pass when the expected key exists with the expected value (as Time)" do
|
51
|
+
now = Time.now
|
52
|
+
{ :time => now }.to_json.should have_json_node(:time).with(now)
|
53
|
+
end
|
54
|
+
|
20
55
|
it "should fail when the expected key exist but the expected value don't exist" do
|
21
56
|
expect {
|
22
|
-
|
57
|
+
{ :product => 'payment-gateway' }.to_json.should have_json_node(:product).with('email-marketing')
|
23
58
|
}.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '{"product":"payment-gateway"}'})
|
24
59
|
end
|
25
60
|
|
@@ -30,25 +65,111 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
30
65
|
end
|
31
66
|
end
|
32
67
|
|
33
|
-
context 'expected key and value
|
34
|
-
it "should pass when the expected key
|
35
|
-
{ :
|
68
|
+
context 'expected key and nil value' do
|
69
|
+
it "should pass when the expected key exists" do
|
70
|
+
{ :product => nil }.to_json.should have_json_node(:product)
|
36
71
|
end
|
37
72
|
|
38
|
-
it "should pass when the expected key and expected value
|
39
|
-
{ :
|
73
|
+
it "should pass when the expected key exists and the expected value is nil" do
|
74
|
+
{ :product => nil }.to_json.should have_json_node(:product).with( nil )
|
40
75
|
end
|
41
76
|
|
42
|
-
it "should fail when the expected key
|
77
|
+
it "should fail when the expected key exist but the expected value don't exist" do
|
43
78
|
expect {
|
44
|
-
|
45
|
-
}.to fail_with(%Q{expected to have node called: '
|
79
|
+
{ :product => nil }.to_json.should have_json_node(:product).with('email-marketing')
|
80
|
+
}.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '{"product":null}'})
|
46
81
|
end
|
82
|
+
end
|
47
83
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
84
|
+
context 'expected key and value in more deep in the JSON' do
|
85
|
+
context '.to_json used' do
|
86
|
+
it "should pass when the expected key exist" do
|
87
|
+
{ :transaction => { :id => 150 } }.to_json.should have_json_node(:id)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should pass when the expected key and expected value exist" do
|
91
|
+
{ :transaction => { :error => { :code => '999' } } }.to_json.should have_json_node(:code).with('999')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should pass when the expected key and expected value exist in very deep" do
|
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
|
+
end
|
97
|
+
|
98
|
+
it "should pass when the expected key and expected value exist in very deep" do
|
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
|
+
end
|
101
|
+
|
102
|
+
it "should fail when the expected key does not exist" do
|
103
|
+
expect {
|
104
|
+
{ :transaction => { :id => 150, :error => {} } }.to_json.should have_json_node(:code)
|
105
|
+
}.to fail_with(%Q{expected to have node called: 'code'. Got: '{"transaction":{"id":150,"error":{}}}'})
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should fail when the expected key exist but don't exist the expected value" do
|
109
|
+
expect {
|
110
|
+
{ :transaction => { :id => 150, :error => { :code => '999' } } }.to_json.should have_json_node(:code).with('001')
|
111
|
+
}.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context 'json string used' do
|
115
|
+
it "should pass when the expected key exist" do
|
116
|
+
'{ "transaction": {"id": 150 } }'.should have_json_node(:id)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should pass when the expected key and expected value exist" do
|
120
|
+
'{ "transaction": {"error": { "code": "999" } } }'.should have_json_node(:code).with('999')
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should pass when the expected key exist with the expected value (as integer)" do
|
124
|
+
'{"number":1 }'.should have_json_node(:number).with(1)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should pass when the expected key exist with the expected value (as boolean)" do
|
128
|
+
'{"boolean":true}'.should have_json_node(:boolean).with(true)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should pass when the expected key exists with the expected value (as DateTime)" do
|
132
|
+
now = DateTime.parse( "2012-09-18T15:42:12-07:00" )
|
133
|
+
'{"date": "2012-09-18T15:42:12-07:00"}'.should have_json_node(:date).with(now)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should pass when the expected key exists with the expected value (as Date)" do
|
137
|
+
now = Date.parse( "2012-09-18" )
|
138
|
+
'{"date": "2012-09-18"}'.should have_json_node(:date).with(now)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should pass when the expected key exists with the expected value (as Time)" do
|
142
|
+
now = Time.parse("2012-09-18T15:42:12Z")
|
143
|
+
'{"time": "2012-09-18T15:42:12+00:00"}'.should have_json_node(:time).with(now)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should pass when the expected key exist with the expected value (as boolean) in a multi node" do
|
147
|
+
'{"uid":"123456","boolean":true}'.should have_json_node(:boolean).with(true)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should pass when the expected key and expected value exist in very deep" do
|
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
|
+
end
|
153
|
+
|
154
|
+
it "should pass when the expected key and expected value exist in very deep" do
|
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
|
+
end
|
157
|
+
|
158
|
+
it "should pass when the expected key and including text exist" do
|
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
|
+
end
|
161
|
+
|
162
|
+
it "should fail when the expected key does not exist" do
|
163
|
+
expect {
|
164
|
+
'{"transaction":{"id":150,"error":{}}}'.should have_json_node(:code)
|
165
|
+
}.to fail_with(%Q{expected to have node called: 'code'. Got: '{"transaction":{"id":150,"error":{}}}'})
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should fail when the expected key exist but don't exist the expected value" do
|
169
|
+
expect {
|
170
|
+
'{"transaction":{"id":150,"error":{"code":"999"}}}'.should have_json_node(:code).with('001')
|
171
|
+
}.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
|
172
|
+
end
|
52
173
|
end
|
53
174
|
end
|
54
175
|
|
@@ -76,7 +197,7 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
76
197
|
|
77
198
|
it "should fail when the expected key exist" do
|
78
199
|
expect {
|
79
|
-
|
200
|
+
{ :status => 'paid' }.to_json.should_not have_json_node(:status)
|
80
201
|
}.to fail_with(%Q{expected to NOT have node called: 'status'. Got: '{"status":"paid"}'})
|
81
202
|
end
|
82
203
|
|
@@ -86,7 +207,7 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
|
|
86
207
|
|
87
208
|
it "should fail when have the expected key and have the expected value" do
|
88
209
|
expect {
|
89
|
-
|
210
|
+
{ :status => 'paid' }.to_json.should_not have_json_node(:status).with('paid')
|
90
211
|
}.to fail_with(%Q{expected to NOT have node called: 'status' with value: 'paid'. Got: '{"status":"paid"}'})
|
91
212
|
end
|
92
213
|
|
@@ -30,7 +30,7 @@ describe APIMatchers::ResponseBody::HaveXmlNode do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context 'expected key and value in more deep in the
|
33
|
+
context 'expected key and value in more deep in the XML' do
|
34
34
|
it "should pass when the expected key exist" do
|
35
35
|
"<transaction><id>150</id></transaction>".should have_xml_node(:id)
|
36
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08
|
12
|
+
date: 2012-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.10.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.10.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: activesupport
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 3.2.5
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.5
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: nokogiri
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: 1.5.2
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.2
|
47
62
|
description: Collection of RSpec matchers for create your API.
|
48
63
|
email:
|
49
64
|
- tomas_stefano@successoft.com
|
@@ -61,6 +76,7 @@ files:
|
|
61
76
|
- Rakefile
|
62
77
|
- api_matchers.gemspec
|
63
78
|
- lib/api_matchers.rb
|
79
|
+
- lib/api_matchers/core/exceptions.rb
|
64
80
|
- lib/api_matchers/core/find_in_json.rb
|
65
81
|
- lib/api_matchers/core/rspec_matchers.rb
|
66
82
|
- lib/api_matchers/core/setup.rb
|
@@ -112,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
128
|
version: '0'
|
113
129
|
requirements: []
|
114
130
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.8.
|
131
|
+
rubygems_version: 1.8.24
|
116
132
|
signing_key:
|
117
133
|
specification_version: 3
|
118
134
|
summary: Collection of RSpec matchers for create your API.
|