lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.1.2 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.1.3

- old
+ new

@@ -227,13 +227,16 @@ result = xpath_elements_for(response: response, xpath: path, attribute: attribute).first raise NoElementAtPath, "No value at Xpath '#{path}'" unless result return result.inner_text if attribute.nil? return result.attributes[attribute].inner_text when :json - matching_values = json_path_values_for(response, path, attribute: attribute) - raise NoElementAtPath, "Element in #{response.body} not found with path '#{path}'" if matching_values.empty? - matching_values.first + paths_to_check = path.split(',') + matching_values = paths_to_check.collect do |path_to_check| + json_path_values_for(response, path_to_check, attribute: attribute) + end.reject(&:empty?) + raise NoElementAtPath, "Path '#{path}' not found in '#{response.body}'" if matching_values.empty? + matching_values.first.first when :hash response.dig(path.split('.')) # Use path as Hash dig expression separating params via '.' TODO: Unit test else response.to_s[/path/] # Perform regular expression using path if not XML nor JSON TODO: Unit test end @@ -271,10 +274,10 @@ # @return [String] Payload to send in REST request def post_data(test_values) if test_values[:body] test_values[:payload] = JSON.generate(hash_used_in_request(test_values[:body])).to_s elsif @request_option == :template - request_body = File.read('template/' + template_name) + request_body = File.read(File.join(Soaspec.template_folder, template_name)) ERB.new(request_body).result(binding) else test_values[:payload] end end \ No newline at end of file