#!/usr/bin/env ruby require 'getoptlong' require 'fileutils' def usage msg = <<-EOF To create a local snapshot from the current installed version: whirlwind --snapshot /some/path/ General options: --environment # set to a name that is used to organize your fixture data. For example, test, dev, prod --browser # set to a valid selenium-webdriver supported browser --site # optional, if the test site name is provided run all features # for that site. If this is not provided pass a feature file as the last argument To execute the example demo site test. This assumes you have started the demo site located under demo_test_site. cd /local/snapshot/dir ./bin/whirlwind --site sites/demo --browser ff --environment test Test results are stored under sites//results. EOF puts msg exit 1 end raise StandardError unless RUBY_VERSION =~ /^1\.9\.\d$/ usage unless ARGV.length > 0 args = ARGV.dup begin opts = GetoptLong.new([ '--snapshot', '-s', GetoptLong::REQUIRED_ARGUMENT ], [ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ], [ '--browser', '-b', GetoptLong::REQUIRED_ARGUMENT ], [ '--site', '-i', GetoptLong::REQUIRED_ARGUMENT ] ) site = '' $browser_type = nil opts.each { |opt, arg| if opt == '--snapshot' || opt == '-s' raise ArgumentError, "Please provide a valid directory." unless File.directory?(arg) dir = File.expand_path(File.dirname(__FILE__) + '/..') base = File.basename(dir) FileUtils.cp_r dir, arg FileUtils.chmod 0700, "#{arg}/#{base}/bin/whirlwind" exit 0 end if opt == '--environment' || opt == '-e' $environment = arg.to_sym end if opt == '--browser' || opt == '-b' $browser_type = arg end if opt == '--site' || opt == '-i' site = File.expand_path(arg) $site_name = File.basename site puts "SITE: #{site}" unless File.directory?(site) puts "Can't find site: #{site}" exit 1 end FileUtils.chdir(site) end } rescue => e end if site == '' if File.exists?(args.last) full_p = File.expand_path(args.last) p = File.expand_path(File.dirname(args.last) + '/..') $site_name = File.basename p FileUtils.chdir(p) args.delete(args.last) args << full_p else puts "Either a site name using option --site or a feature file to execute" exit 1 end end delete_items = %w(--snapshot -s --environment -e --site -i --browser -b) delete_items.each { |i| index = args.rindex(i) if index next_ = args[index+1] args.delete_at(index) args.delete(next_) end } args += ['-f', 'Cucumber::Formatter::HtmlImage', '--out', 'tmp.html', '-f', 'pretty'] require 'cucumber' Cucumber::Cli::Main.execute(args)