#!/usr/bin/env jruby require 'rubygems' require 'optparse' require 'ostruct' require 'rbconfig' require 'rspec' require 'operawatir' # Encoding fix $KCODE = "UTF8" class Options def self.parse(args) options = OpenStruct.new options.ng = false options.inspectr = ENV['OPERA_INSPECTR'] || '' options.color = Config::CONFIG['host_os'] =~ /mswin|msys|mingw32/ ? false : true options.check_syntax = false options.format = 'progress' options.executable = ENV['OPERA_PATH'] || '' options.options = ENV['OPERA_ARGS'] || '' opts = OptionParser.new do |opts| opts.banner = "Usage: operawatir [--ng] [-i|--inspectr] [--color] [-c|--check-syntax]\n" + " [-f|--format=FORMAT[:OUT_FILE]] [-e|--executable=BINARY] [-o|--options=OPTIONS]\n" + " [-h|--help] [-v|--version] FILES" opts.separator "" opts.separator "Specific options:" opts.on('--ng', 'Connect to Nailgun server instead of starting our ', 'own JVM') do |ng| options.ng = ng end opts.on('-i', '--inspectr', 'Attach inspectr to browser instance') do |i| options.inspectr = i end opts.on('--color', 'Enable colorized output (default: enabled)') do |c| options.color = c end opts.on('-c', '--check-syntax', 'Check syntax only') do |c| options.check_syntax = c end opts.on('-f', '--format=FORMAT[:OUT_FILE]', [:OperaHelperFormatter, :SpartanFormatter, :progress, :documentation], 'Specify RSpec output format (OperaHelperFormatter,', 'SpartanFormatter, Specdoc) and optionally an output', 'file') do |t| options.format = t end opts.on('-e', '--executable=EXECUTABLE', 'Browser to run the test with. ', 'Will override environmental variable OPERA_PATH') do |e| options.executable = e end opts.on('-o', '--options=OPTIONS', 'Options passed to the optional executable. ', 'Will override environmental variable OPERA_ARGS') do |o| options.options = o end opts.separator '' opts.separator 'Common options:' opts.on_tail('-h', '--help', 'Show this message') do abort opts end opts.on_tail('-v', '--version', 'Show version') do abort "OperaWatir version #{OperaWatir.version}" end end opts.parse!(args) options end end options = Options.parse(ARGV) abort 'operawatir: You need to specify at least one test file to run' if ARGV.empty? abort 'operawatir: --ng and --check-syntax is disabled for now' if options.ng or options.check_syntax RSpec.configure do |c| c.color_enabled = options.color c.formatter = options.format c.files_to_run = ARGV c.formatter = "documentation" end require 'operawatir/desktop-waiter' OperaWatir::Waiter.configure do |c| c.path = options.executable c.args = options.options c.inspectr = options.inspectr end OperaWatir::Waiter.run!