Class: Cucumber::Cli::Configuration

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Constantize
Defined in:
lib/cucumber/cli/configuration.rb

Defined Under Namespace

Classes: LogFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cucumber::Constantize

#constantize, #underscore

Constructor Details

#initialize(out_stream = STDOUT, error_stream = STDERR) ⇒ Configuration

Returns a new instance of Configuration.



17
18
19
20
21
# 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

Instance Attribute Details

#out_streamObject (readonly)

Returns the value of attribute out_stream.



15
16
17
# File 'lib/cucumber/cli/configuration.rb', line 15

def out_stream
  @out_stream
end

Instance Method Details

#all_files_to_loadObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cucumber/cli/configuration.rb', line 77

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

#dry_run?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/cucumber/cli/configuration.rb', line 57

def dry_run?
  @options[:dry_run]
end

#expand?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/cucumber/cli/configuration.rb', line 61

def expand?
  @options[:expand]
end

#feature_dirsObject



119
120
121
122
123
# File 'lib/cucumber/cli/configuration.rb', line 119

def feature_dirs
  dirs = paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
  dirs.delete('.') unless paths.include?('.')
  with_default_features_path(dirs)
end

#feature_filesObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cucumber/cli/configuration.rb', line 102

def feature_files
  potential_feature_files = with_default_features_path(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(/(.*?\.feature.*?) /).collect(&:strip).reject(&:empty?)
    else
      path
    end
  end.flatten.uniq
  remove_excluded_files_from(potential_feature_files)
  potential_feature_files
end

#filtersObject



150
151
152
# File 'lib/cucumber/cli/configuration.rb', line 150

def filters
  @options.filters
end

#formatsObject



154
155
156
# File 'lib/cucumber/cli/configuration.rb', line 154

def formats
  @options[:formats]
end

#formatter_class(format) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/cucumber/cli/configuration.rb', line 69

def formatter_class(format)
  if(builtin = Options::BUILTIN_FORMATS[format])
    constantize(builtin[0])
  else
    constantize(format)
  end
end

#formatter_factoriesObject



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/cucumber/cli/configuration.rb', line 167

def formatter_factories
  @options[:formats].map do |format_and_out|
    format = format_and_out[0]
    path_or_io = format_and_out[1]
    begin
      factory = formatter_class(format)
      yield factory, path_or_io, @options
    rescue Exception => e
      e.message << "\nError creating formatter: #{format}"
      raise e
    end
  end
end

#guess?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/cucumber/cli/configuration.rb', line 53

def guess?
  @options[:guess]
end

#logObject



125
126
127
128
129
130
131
# File 'lib/cucumber/cli/configuration.rb', line 125

def log
  logger = Logger.new(@out_stream)
  logger.formatter = LogFormatter.new
  logger.level = Logger::INFO
  logger.level = Logger::DEBUG if self.verbose?
  logger
end

#name_regexpsObject



146
147
148
# File 'lib/cucumber/cli/configuration.rb', line 146

def name_regexps
  @options[:name_regexps]
end

#optionsObject



158
159
160
161
# File 'lib/cucumber/cli/configuration.rb', line 158

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) ⇒ Object



23
24
25
26
27
28
29
30
31
# 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?
  # todo: remove
  @options[:tag_expression] = Gherkin::TagExpression.new(@options[:tag_expressions])
  set_environment_variables
end

#pathsObject



163
164
165
# File 'lib/cucumber/cli/configuration.rb', line 163

def paths
  @options[:paths]
end

#randomize?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/cucumber/cli/configuration.rb', line 37

def randomize?
  @options[:order] == 'random'
end

#seedObject



41
42
43
# File 'lib/cucumber/cli/configuration.rb', line 41

def seed
  Integer(@options[:seed] || rand(0xFFFF))
end

#snippet_typeObject



65
66
67
# File 'lib/cucumber/cli/configuration.rb', line 65

def snippet_type
  @options[:snippet_type] || :regexp
end

#step_defs_to_loadObject



91
92
93
# File 'lib/cucumber/cli/configuration.rb', line 91

def step_defs_to_load
  all_files_to_load.reject {|f| f =~ %r{/support/} }
end

#strict?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cucumber/cli/configuration.rb', line 45

def strict?
  @options[:strict]
end

#support_to_loadObject



95
96
97
98
99
100
# File 'lib/cucumber/cli/configuration.rb', line 95

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_expressionObject

todo: remove



134
135
136
# File 'lib/cucumber/cli/configuration.rb', line 134

def tag_expression
  Gherkin::TagExpression.new(@options[:tag_expressions])
end

#tag_expressionsObject



142
143
144
# File 'lib/cucumber/cli/configuration.rb', line 142

def tag_expressions
  @options[:tag_expressions]
end

#tag_limitsObject



138
139
140
# File 'lib/cucumber/cli/configuration.rb', line 138

def tag_limits
  tag_expression.limits.to_hash
end

#verbose?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cucumber/cli/configuration.rb', line 33

def verbose?
  @options[:verbose]
end

#wip?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cucumber/cli/configuration.rb', line 49

def wip?
  @options[:wip]
end