require_relative 'methods/required_files' #==================================== # INTERACTION STEPS #==================================== # Step used to execute a SQL script on a specific schema And /^I run sql script "([^\"]*)" on "([^\"]*)" schema$/ do |script, schema| begin sql = "#{script}" DatabaseMethods.execute_select(schema, sql) DatabaseMethods.close_connection(schema) ensure end end # Step used to execute SQL script from SQL file on specific schema Given /^I run sql script from file "([^\"]*)" on "([^\"]*)" schema$/ do |sql_script, schema| if sql_script != nil and sql_script != "" begin File.readlines($sql_dir + sql_script).each do |line| if line.nil? || line =~ /^\s*\n*--/ # puts "\nSQL: " + line; next; end line = line.strip(); line = line[0..-2]; #puts "\nSQL: " + line; DatabaseMethods.execute_select(schema, line) sleep(1); end DatabaseMethods.close_connection(schema) end end end # Step used to check if data exists in database or not with condition in file Then /^I should ( not)? see data in schema "(.*)" database with SQL query in file "(.*)"$/ do |negative, schema, file| sql = File.read($sql_dir + file) filepath = ($sql_dir + file) if File.exist?(filepath) begin rs = DatabaseMethods.execute_select(schema, sql) obj_array = Array.new rs.each { |row| row.each_pair { |col, value| assert(false) if negative.nil? && value == 0 || !negative.nil? && value == 1 } } ensure DatabaseMethods.close_connection(schema) end else raise "*** ERROR: Please check #{filepath} exists." end end