#!/usr/bin/env ruby require 'aipim-rails' # root do aipim path = File.expand_path(File.dirname(__FILE__))+"/../" # pegar o nome dos arquivos das features def get_files files = [] ARGV.delete_at(0) ARGV.each do |arg| ls = %x[ls #{arg}].split("\n") ls.each do |f| f = f.split("/") f.delete_at(0) if f[0] == "features" f = f[0] files << f if !(f =~ /.feature\z/).nil? end end files end if ARGV[0] == 'generate' # Cria a pasta do aipim system('mkdir -p aipim') # Cria pasta screenshot system('mkdir -p aipim/screenshots') # Cria um arquivo em branco para o github nao encher o saco system('touch aipim/screenshots/empty') # Cria a pasta das paginas html geradas pelo aipim system('mkdir -p aipim/html') # Cria a pasta costum do HTML system('mkdir -p aipim/html/costum') system('cp -n '+path+'lib/assets/costum.css aipim/html/costum') system('cp -n '+path+'lib/assets/costum.js aipim/html/costum') # Bootstrap system('cp '+path+'lib/assets/bootstrap.min.css aipim/html') # jQuery system('cp '+path+'lib/assets/jquery-1.9.1.js aipim/html') # resolucao padrão width = "1366" height = "768" screenshot = true # argumentos ARGV.each_with_index do |arg, i| if i > 0 # argumento da resolucao if ARGV[i] == '--resolution' width = ARGV[i+1].split("x")[0] height = ARGV[i+1].split("x")[1] # argumento do screenshot elsif ARGV[i] == '--no-screenshot' screenshot = false end end end if screenshot # le o arquivo de configuracao do screenshot f = File.open(path+'lib/webdriver/screenshot.rb', "r") # salva tudo numa string f_str = "" f.each_line {|line| f_str = f_str + line} # substitui os valores da resolucao f_str = f_str.gsub("SCREENSHOT_HEIGHT", height).gsub("SCREENSHOT_WIDTH", width) f.close # abre o arquivo de configuracao do screenshot na pasta do cucumber f = File.open("features/support/screenshot.rb", "w") # coloca a string nesse arquivo f.puts f_str f.close else system('rm -f features/support/screenshot.rb') end elsif ARGV[0] == 'html' # remove os htmls antigos %x[rm -f aipim/html/*.feature.html] # pega o nome das features files = get_files # recebe o features master features = [] files.each do |f| features << Parser.init(f) end # gera a index do relatorio ConvertToHtml.index(features) # geara o html das features ConvertToHtml.features(features) # nao serve para nada!! é śó de DEBUG!! elsif ARGV[0] == 'parser' files = get_files files.each do |f| puts "Tentando abrir arquivo #{f}" feature = Parser.init(f) puts "Feature name: #{feature[:feature_name]}" puts "Feature description: " feature[:feature_description].each {|t| puts t} puts "Context name: #{feature[:context_name]}" puts "Context description" feature[:context_description].each {|t| puts t} feature[:scenarios].each do |scenario| puts "----------------------------------------------" puts scenario[:name] scenario[:steps].each {|step| puts step} end end end