| 
									
										
										
										
											2014-06-20 12:59:17 +04:00
										 |  |  | Then(/^response array should contains elements like:$/) do |string| | 
					
						
							| 
									
										
										
										
											2015-10-06 13:50:26 +03:00
										 |  |  |   src = JSON.parse(string) | 
					
						
							| 
									
										
										
										
											2014-06-20 12:59:17 +04:00
										 |  |  |   array = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   array.each do |e| | 
					
						
							|  |  |  |     src.each do |key, value| | 
					
						
							|  |  |  |       assert e.key?(key), "Element #{e.inspect} has no key '#{key}'" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^response array should be empty$/) do | 
					
						
							|  |  |  |   array = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   assert array.empty?, "Array is not empty" | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2014-06-23 13:58:14 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | Then(/^response object should be empty$/) do | 
					
						
							|  |  |  |   obj = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   assert obj.empty?, "Object is not empty" | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^the JSON response should be an array$/) do | 
					
						
							|  |  |  |   body = JSON.parse(last_response.body) | 
					
						
							| 
									
										
										
										
											2014-07-03 13:26:29 +04:00
										 |  |  |   assert body.is_a?(Array), "Body is not an array: #{last_response.body}" | 
					
						
							| 
									
										
										
										
											2014-06-23 13:58:14 +04:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^the JSON response should be an object$/) do | 
					
						
							|  |  |  |   body = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   assert body.is_a?(Hash), "Body is not an object" | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^the array elements should be strings$/) do | 
					
						
							|  |  |  |   body = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   body.each do |e| | 
					
						
							|  |  |  |     assert e.is_a?(String), "Array element is not a string" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^response should be JSON object like:$/) do |string| | 
					
						
							|  |  |  |   src = JSON.parse(string) | 
					
						
							|  |  |  |   obj = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   src.each do |key, value| | 
					
						
							|  |  |  |     assert obj.key?(key), "Object has no key '#{key}'" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2014-07-03 13:26:29 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | Then(/^the array should contains strings '(.*)'$/) do |string| | 
					
						
							| 
									
										
										
										
											2015-10-06 13:50:26 +03:00
										 |  |  |   buf = string.split(",").map(&:strip) | 
					
						
							| 
									
										
										
										
											2014-07-03 13:26:29 +04:00
										 |  |  |   array = JSON.parse(last_response.body) | 
					
						
							| 
									
										
										
										
											2015-10-06 13:50:26 +03:00
										 |  |  |   res = buf - array | 
					
						
							|  |  |  |   assert res.empty?, "Response has no strings '#{res.join("', '")}'" | 
					
						
							| 
									
										
										
										
											2014-07-03 13:26:29 +04:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^the array should not contains strings '(.*)'$/) do |string| | 
					
						
							| 
									
										
										
										
											2015-10-06 13:50:26 +03:00
										 |  |  |   buf = string.split(",").map(&:strip) | 
					
						
							| 
									
										
										
										
											2014-07-03 13:26:29 +04:00
										 |  |  |   array = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   buf.each do |v| | 
					
						
							|  |  |  |     assert !array.include?(v), "Array should not contains '#{v}'" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^the object should contains key '(.*)' with array and array should contains strings '(.*)'$/) do |key, string| | 
					
						
							|  |  |  |   buf = string.split(",") | 
					
						
							|  |  |  |   obj = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   assert obj.key?(key), "Object should has a key '#{key}'" | 
					
						
							|  |  |  |   assert obj[key].is_a?(Array), "Object should has an array '#{key}'" | 
					
						
							|  |  |  |   buf.each do |v| | 
					
						
							|  |  |  |     assert obj[key].include?(v), "'#{key}' array should contains '#{v}'" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Then(/^the object should contains key '(.*)' with array and array should not contains strings '(.*)'$/) do |key, string| | 
					
						
							|  |  |  |   buf = string.split(",") | 
					
						
							|  |  |  |   obj = JSON.parse(last_response.body) | 
					
						
							|  |  |  |   assert obj.key?(key), "Object should has a key '#{key}'" | 
					
						
							|  |  |  |   assert obj[key].is_a?(Array), "Object should has an array '#{key}'" | 
					
						
							|  |  |  |   buf.each do |v| | 
					
						
							|  |  |  |     assert !obj[key].include?(v), "'#{key}' array should not contains '#{v}'" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 |