class Teaspoon::CommandLine

Public Class Methods

new() click to toggle source
# File lib/teaspoon/command_line.rb, line 10
def initialize
  @options = {}
  @options[:files] = opt_parser.parse!

  require_console
  Teaspoon.abort(nil, 1) if Teaspoon::Console.new(@options).failures?
rescue Teaspoon::EnvironmentNotFound => e
  Teaspoon.abort("#{e.message} Consider using --require=path/to/teaspoon_env.rb")
end

Public Instance Methods

opt_parser() click to toggle source
# File lib/teaspoon/command_line.rb, line 20
def opt_parser
  OptionParser.new do |parser|
    @parser = parser
    @parser.banner = "Usage: teaspoon [options] [files]\n\n"

    opts_for_general
    opts_for_filtering
    opts_for_output
    opts_for_coverage
    opts_for_utility
  end
end

Protected Instance Methods

opts_for_coverage() click to toggle source
# File lib/teaspoon/command_line.rb, line 99
def opts_for_coverage
  separator("Coverage")

  opt :use_coverage, "-C", "--coverage CONFIG_NAME",
      "Generate coverage reports using a pre-defined coverage configuration."
end
opts_for_filtering() click to toggle source
# File lib/teaspoon/command_line.rb, line 72
def opts_for_filtering
  separator("Filtering")

  opt :suite, "-s", "--suite SUITE",
      "Focus to a specific suite."

  opt :filter, "-g", "--filter FILTER",
      "Filter tests matching a specific filter."
end
opts_for_general() click to toggle source
# File lib/teaspoon/command_line.rb, line 35
def opts_for_general
  opt :environment, "-r", "--require FILE",
      "Require Teaspoon environment file."

  # opt :custom_options_file,
  #     "-O", "--options PATH",
  #     "Specify the path to a custom options file."

  opt :driver, "-d", "--driver DRIVER",
      "Specify driver:",
      *driver_details

  opt :driver_options, "--driver-options OPTIONS",
      "Specify driver-specific options to pass into the driver.",
      "  e.g. \"--ssl-protocol=any --ssl-certificates-path=/path/to/certs\".",
      "  Driver options are only supported with phantomjs."

  opt :driver_timeout, "--driver-timeout SECONDS",
      "Sets the timeout for the driver to wait before exiting."

  opt :server, "--server SERVER",
      "Sets server to use with Rack.",
      "  e.g. webrick, thin"

  opt :server_host, "--server-host HOST",
      "Sets the server to use a specific host."

  opt :server_port, "--server-port PORT",
      "Sets the server to use a specific port."

  opt :server_timeout, "--server-timeout SECONDS",
      "Sets the timeout that the server must start within."

  opt :fail_fast, "-F", "--[no-]fail-fast",
      "Abort after the first failing suite."
end
opts_for_output() click to toggle source
# File lib/teaspoon/command_line.rb, line 82
def opts_for_output
  separator("Output")

  opt :suppress_log, "-q", "--[no-]suppress-log",
      "Suppress logs coming from console[log/debug/error]."

  opt :color, "-c", "--[no-]color",
      "Enable/Disable color output."

  opt :export, "-e", "--export [OUTPUT_PATH]",
      "Exports the test suite as the full HTML (requires wget)."

  opt :formatters, "-f", "--format FORMATTERS",
      "Specify formatters (comma separated)",
      *formatter_details
end
opts_for_utility() click to toggle source
# File lib/teaspoon/command_line.rb, line 106
def opts_for_utility
  separator("Utility")

  @parser.on "-v", "--version", "Display the version." do
    Teaspoon.abort(Teaspoon::VERSION, 0)
  end

  @parser.on "-h", "--help", "You're looking at it." do
    Teaspoon.abort(@parser, 0)
  end
end

Private Instance Methods

driver_details() click to toggle source
# File lib/teaspoon/command_line.rb, line 138
def driver_details
  Teaspoon::Driver.available.map do |name, options|
    "  #{name}#{' (default)' if options[:default]}"
  end
end
formatter_details() click to toggle source
# File lib/teaspoon/command_line.rb, line 132
def formatter_details
  Teaspoon::Formatter.available.map do |name, options|
    "  #{name}#{' (default)' if options[:default]} - #{options[:description]}"
  end
end
opt(config, *args) click to toggle source
# File lib/teaspoon/command_line.rb, line 124
def opt(config, *args)
  @parser.on(*args, proc { |value| @options[config] = value })
end
require_console() click to toggle source
# File lib/teaspoon/command_line.rb, line 128
def require_console
  require "teaspoon/console"
end
separator(message) click to toggle source
# File lib/teaspoon/command_line.rb, line 120
def separator(message)
  @parser.separator("\n  **** #{message} ****\n\n")
end