class Cucumber::Cli::Configuration

Attributes

out_stream[R]

Public Class Methods

new(out_stream = STDOUT, error_stream = STDERR) click to toggle source
# File lib/cucumber/cli/configuration.rb, line 17
def initialize(out_stream = STDOUT, error_stream = STDERR)
  @out_stream   = out_stream
  @error_stream = error_stream
  @options = Options.new(@out_stream, @error_stream, :default_profile => 'default')
end

Public Instance Methods

all_files_to_load() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 83
def all_files_to_load
  requires = @options[:require].empty? ? require_dirs : @options[:require]
  files = requires.map do |path|
    path = path.gsub(/\/, '/') # In case we're on windows. Globs don't work with backslashes.
    path = path.gsub(/\/$/, '') # Strip trailing slash.
    File.directory?(path) ? Dir["#{path}/**/*"] : path
  end.flatten.uniq
  remove_excluded_files_from(files)
  files.reject! {|f| !File.file?(f)}
  files.reject! {|f| File.extname(f) == '.feature' }
  files.reject! {|f| f =~ /^http/}
  files.sort
end
build_tree_walker(step_mother) click to toggle source
# File lib/cucumber/cli/configuration.rb, line 71
def build_tree_walker(step_mother)
  Ast::TreeWalker.new(step_mother, formatters(step_mother), self)
end
dotcucumber() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 67
def dotcucumber
  @options[:dotcucumber]
end
drb?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 51
def drb?
  @options[:drb]
end
drb_port() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 55
def drb_port
  @options[:drb_port].to_i if @options[:drb_port]
end
dry_run?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 59
def dry_run?
  @options[:dry_run]
end
expand?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 63
def expand?
  @options[:expand]
end
feature_dirs() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 125
def feature_dirs
  paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
end
feature_files() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 108
def feature_files
  potential_feature_files = paths.map do |path|
    path = path.gsub(/\/, '/') # In case we're on windows. Globs don't work with backslashes.
    path = path.chomp('/')
    if File.directory?(path)
      Dir["#{path}/**/*.feature"].sort
    elsif path[0..0] == '@' and # @listfile.txt
        File.file?(path[1..-1]) # listfile.txt is a file
      IO.read(path[1..-1]).split
    else
      path
    end
  end.flatten.uniq
  remove_excluded_files_from(potential_feature_files)
  potential_feature_files
end
filters() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 141
def filters
  @options.filters
end
formats() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 145
def formats
  @options[:formats]
end
formatter_class(format) click to toggle source
# File lib/cucumber/cli/configuration.rb, line 75
def formatter_class(format)
  if(builtin = Options::BUILTIN_FORMATS[format])
    constantize(builtin[0])
  else
    constantize(format)
  end
end
guess?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 47
def guess?
  @options[:guess]
end
log() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 129
def log
  logger = Logger.new(@out_stream)
  logger.formatter = LogFormatter.new
  logger.level = Logger::INFO
  logger.level = Logger::DEBUG if self.verbose?
  logger
end
options() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 149
def options
  warn("Deprecated: Configuration#options will be removed from the next release of Cucumber. Please use the configuration object directly instead.")
  @options
end
parse!(args) click to toggle source
# File lib/cucumber/cli/configuration.rb, line 23
def parse!(args)
  @args = args
  @options.parse!(args)
  arrange_formats
  raise("You can't use both --strict and --wip") if strict? && wip?

  @options[:tag_expression] = Gherkin::TagExpression.new(@options[:tag_expressions])
  return @args.replace(@options.expanded_args_without_drb) if drb?

  set_environment_variables
end
paths() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 154
def paths
  @options[:paths].empty? ? ['features'] : @options[:paths]
end
step_defs_to_load() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 97
def step_defs_to_load
  all_files_to_load.reject {|f| f =~ %r{/support/} }
end
strict?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 39
def strict?
  @options[:strict]
end
support_to_load() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 101
def support_to_load
  support_files = all_files_to_load.select {|f| f =~ %r{/support/} }
  env_files = support_files.select {|f| f =~ %r{/support/env\..*} }
  other_files = support_files - env_files
  @options[:dry_run] ? other_files : env_files + other_files
end
tag_expression() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 137
def tag_expression
  Gherkin::TagExpression.new(@options[:tag_expressions])
end
verbose?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 35
def verbose?
  @options[:verbose]
end
wip?() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 43
def wip?
  @options[:wip]
end

Private Instance Methods

arrange_formats() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 193
def arrange_formats
  @options[:formats] << ['pretty', @out_stream] if @options[:formats].empty?
  @options[:formats] = @options[:formats].sort_by{|f| f[1] == @out_stream ? -1 : 1}
  streams = @options[:formats].map { |(_, stream)| stream }
  if streams != streams.uniq
    raise "All but one formatter must use --out, only one can print to each stream (or STDOUT)"
  end
end
formatters(step_mother) click to toggle source
# File lib/cucumber/cli/configuration.rb, line 159
def formatters(step_mother)
  # TODO: We should remove the autoformat functionality. That
  # can be done with the gherkin CLI.
  if @options[:autoformat]
    require 'cucumber/formatter/pretty'
    return [Formatter::Pretty.new(step_mother, nil, @options)]
  end

  @options[:formats].map do |format_and_out|
    format = format_and_out[0]
    path_or_io = format_and_out[1]
    begin
      formatter_class = formatter_class(format)
      formatter_class.new(step_mother, path_or_io, @options)
    rescue Exception => e
      e.message << "\nError creating formatter: #{format}"
      raise e
    end
  end
end
remove_excluded_files_from(files) click to toggle source
# File lib/cucumber/cli/configuration.rb, line 202
def remove_excluded_files_from(files)
  files.reject! {|path| @options[:excludes].detect {|pattern| path =~ pattern } }
end
require_dirs() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 206
def require_dirs
  feature_dirs + Dir['vendor/{gems,plugins}/*/cucumber']
end
set_environment_variables() click to toggle source
# File lib/cucumber/cli/configuration.rb, line 187
def set_environment_variables
  @options[:env_vars].each do |var, value|
    ENV[var] = value
  end
end