# File lib/cucumber/cli/options.rb, line 56 56: def initialize(out_stream = STDOUT, error_stream = STDERR, options = {}) 57: @out_stream = out_stream 58: @error_stream = error_stream 59: 60: @default_profile = options[:default_profile] 61: @skip_profile_information = options[:skip_profile_information] 62: @profiles = [] 63: @overridden_paths = [] 64: @options = default_options 65: 66: @quiet = @disable_profile_loading = nil 67: end
# File lib/cucumber/cli/options.rb, line 69 69: def [](key) 70: @options[key] 71: end
# File lib/cucumber/cli/options.rb, line 73 73: def []=(key, value) 74: @options[key] = value 75: end
# File lib/cucumber/cli/options.rb, line 281 281: def custom_profiles 282: @profiles - [@default_profile] 283: end
# File lib/cucumber/cli/options.rb, line 77 77: def expanded_args_without_drb 78: return @expanded_args_without_drb if @expanded_args_without_drb 79: @expanded_args_without_drb = ( 80: previous_flag_was_profile = false 81: @expanded_args.reject do |arg| 82: if previous_flag_was_profile 83: previous_flag_was_profile = false 84: next true 85: end 86: if [PROFILE_SHORT_FLAG, PROFILE_LONG_FLAG].include?(arg) 87: previous_flag_was_profile = true 88: next true 89: end 90: arg == DRB_FLAG || @overridden_paths.include?(arg) 91: end 92: ) 93: 94: @expanded_args_without_drb.push("--no-profile") unless @expanded_args_without_drb.include?(NO_PROFILE_LONG_FLAG) || @expanded_args_without_drb.include?(NO_PROFILE_SHORT_FLAG) 95: @expanded_args_without_drb 96: end
# File lib/cucumber/cli/options.rb, line 285 285: def filters 286: @options.values_at(:name_regexps, :tag_expressions).select{|v| !v.empty?}.first || [] 287: end
# File lib/cucumber/cli/options.rb, line 98 98: def parse!(args) 99: @args = args 100: @expanded_args = @args.dup 101: 102: @args.extend(::OptionParser::Arguable) 103: 104: @args.options do |opts| 105: opts.banner = ["Usage: cucumber [options] [ [FILE|DIR|URL][:LINE[:LINE]*] ]+", "", 106: "Examples:", 107: "cucumber examples/i18n/en/features", 108: "cucumber @rerun.txt (See --format rerun)", 109: "cucumber examples/i18n/it/features/somma.feature:6:98:113", 110: "cucumber -s -i http://rubyurl.com/eeCl", "", "", 111: ].join("\n") 112: opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR", 113: "Require files before executing the features. If this", 114: "option is not specified, all *.rb files that are", 115: "siblings or below the features will be loaded auto-", 116: "matically. Automatic loading is disabled when this", 117: "option is specified, and all loading becomes explicit.", 118: "Files under directories named \"support\" are always", 119: "loaded first.", 120: "This option can be specified multiple times.") do |v| 121: @options[:require] << v 122: if(Cucumber::JRUBY && File.directory?(v)) 123: require 'java' 124: $CLASSPATH << v 125: end 126: end 127: 128: if(Cucumber::JRUBY) 129: opts.on("-j DIR", "--jars DIR", 130: "Load all the jars under DIR") do |jars| 131: Dir["#{jars}/**/*.jar"].each {|jar| require jar} 132: end 133: end 134: 135: opts.on("--i18n LANG", 136: "List keywords for in a particular language", 137: %{Run with "--i18n help" to see all languages}) do |lang| 138: if lang == 'help' 139: list_languages_and_exit 140: else 141: list_keywords_and_exit(lang) 142: end 143: end 144: opts.on("-f FORMAT", "--format FORMAT", 145: "How to format features (Default: pretty). Available formats:", 146: *FORMAT_HELP) do |v| 147: @options[:formats] << [v, @out_stream] 148: end 149: opts.on("-o", "--out [FILE|DIR]", 150: "Write output to a file/directory instead of STDOUT. This option", 151: "applies to the previously specified --format, or the", 152: "default format if no format is specified. Check the specific", 153: "formatter's docs to see whether to pass a file or a dir.") do |v| 154: @options[:formats] << ['pretty', nil] if @options[:formats].empty? 155: @options[:formats][1][1] = v 156: end 157: opts.on("-t TAG_EXPRESSION", "--tags TAG_EXPRESSION", 158: "Only execute the features or scenarios with tags matching TAG_EXPRESSION.", 159: "Scenarios inherit tags declared on the Feature level. The simplest", 160: "TAG_EXPRESSION is simply a tag. Example: --tags @dev. When a tag in a tag", 161: "expression starts with a ~, this represents boolean NOT. Example: --tags ~@dev.", 162: "A tag expression can have several tags separated by a comma, which represents", 163: "logical OR. Example: --tags @dev,@wip. The --tags option can be specified", 164: "several times, and this represents logical AND. Example: --tags @foo,~@bar --tags @zap.", 165: "This represents the boolean expression (@foo || !@bar) && @zap.", 166: "\n", 167: "Beware that if you want to use several negative tags to exclude several tags", 168: "you have to use logical AND: --tags ~@fixme --tags @buggy.", 169: "\n", 170: "Positive tags can be given a threshold to limit the number of occurrences.", 171: "Example: --tags @qa:3 will fail if there are more than 3 occurrences of the @qa tag.", 172: "This can be practical if you are practicing Kanban or CONWIP.") do |v| 173: @options[:tag_expressions] << v 174: end 175: opts.on("-n NAME", "--name NAME", 176: "Only execute the feature elements which match part of the given name.", 177: "If this option is given more than once, it will match against all the", 178: "given names.") do |v| 179: @options[:name_regexps] << /#{v}/ 180: end 181: opts.on("-e", "--exclude PATTERN", "Don't run feature files or require ruby files matching PATTERN") do |v| 182: @options[:excludes] << Regexp.new(v) 183: end 184: opts.on(PROFILE_SHORT_FLAG, "#{PROFILE_LONG_FLAG} PROFILE", 185: "Pull commandline arguments from cucumber.yml which can be defined as", 186: "strings or arrays. When a 'default' profile is defined and no profile", 187: "is specified it is always used. (Unless disabled, see -P below.)", 188: "When feature files are defined in a profile and on the command line", 189: "then only the ones from the command line are used.") do |v| 190: @profiles << v 191: end 192: opts.on(NO_PROFILE_SHORT_FLAG, NO_PROFILE_LONG_FLAG, 193: "Disables all profile loading to avoid using the 'default' profile.") do |v| 194: @disable_profile_loading = true 195: end 196: opts.on("-c", "--[no-]color", 197: "Whether or not to use ANSI color in the output. Cucumber decides", 198: "based on your platform and the output destination if not specified.") do |v| 199: Term::ANSIColor.coloring = v 200: end 201: opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.", 202: "This also omits the loading of your support/env.rb file if it exists.", 203: "Implies --no-snippets.") do 204: @options[:dry_run] = true 205: @options[:snippets] = false 206: end 207: opts.on("-a", "--autoformat DIR", 208: "Reformats (pretty prints) feature files and write them to DIRECTORY.", 209: "Be careful if you choose to overwrite the originals.", 210: "Implies --dry-run --formatter pretty.") do |directory| 211: @options[:autoformat] = directory 212: Term::ANSIColor.coloring = false 213: @options[:dry_run] = true 214: @quiet = true 215: end 216: 217: opts.on("-m", "--no-multiline", 218: "Don't print multiline strings and tables under steps.") do 219: @options[:no_multiline] = true 220: end 221: opts.on("-s", "--no-source", 222: "Don't print the file and line of the step definition with the steps.") do 223: @options[:source] = false 224: end 225: opts.on("-i", "--no-snippets", "Don't print snippets for pending steps.") do 226: @options[:snippets] = false 227: end 228: opts.on("-q", "--quiet", "Alias for --no-snippets --no-source.") do 229: @quiet = true 230: end 231: opts.on("-b", "--backtrace", "Show full backtrace for all errors.") do 232: Cucumber.use_full_backtrace = true 233: end 234: opts.on("-S", "--strict", "Fail if there are any undefined steps.") do 235: @options[:strict] = true 236: end 237: opts.on("-w", "--wip", "Fail if there are any passing scenarios.") do 238: @options[:wip] = true 239: end 240: opts.on("-v", "--verbose", "Show the files and features loaded.") do 241: @options[:verbose] = true 242: end 243: opts.on("-g", "--guess", "Guess best match for Ambiguous steps.") do 244: @options[:guess] = true 245: end 246: opts.on("-x", "--expand", "Expand Scenario Outline Tables in output.") do 247: @options[:expand] = true 248: end 249: opts.on(DRB_FLAG, "Run features against a DRb server. (i.e. with the spork gem)") do 250: @options[:drb] = true 251: end 252: opts.on("--port PORT", "Specify DRb port. Ignored without --drb") do |port| 253: @options[:drb_port] = port 254: end 255: opts.on_tail("--version", "Show version.") do 256: @out_stream.puts Cucumber::VERSION 257: Kernel.exit(0) 258: end 259: opts.on_tail("-h", "--help", "You're looking at it.") do 260: @out_stream.puts opts.help 261: Kernel.exit(0) 262: end 263: end.parse! 264: 265: if @quiet 266: @options[:snippets] = @options[:source] = false 267: else 268: @options[:snippets] = true if @options[:snippets].nil? 269: @options[:source] = true if @options[:source].nil? 270: end 271: 272: extract_environment_variables 273: @options[:paths] = @args.dup #whatver is left over 274: 275: merge_profiles 276: print_profile_information 277: 278: self 279: end
# File lib/cucumber/cli/options.rb, line 393 393: def default_options 394: { 395: :strict => false, 396: :require => [], 397: :dry_run => false, 398: :formats => [], 399: :excludes => [], 400: :tag_expressions => [], 401: :name_regexps => [], 402: :env_vars => {}, 403: :diff_enabled => true 404: } 405: end
# File lib/cucumber/cli/options.rb, line 333 333: def default_profile_should_be_used? 334: @profiles.empty? && 335: profile_loader.cucumber_yml_defined? && 336: profile_loader.has_profile?(@default_profile) 337: end
# File lib/cucumber/cli/options.rb, line 313 313: def disable_profile_loading? 314: @disable_profile_loading 315: end
# File lib/cucumber/cli/options.rb, line 304 304: def extract_environment_variables 305: @args.delete_if do |arg| 306: if arg =~ /^(\w+)=(.*)$/ 307: @options[:env_vars][$1] = $2 308: true 309: end 310: end 311: end
# File lib/cucumber/cli/options.rb, line 372 372: def list_keywords_and_exit(lang) 373: require 'gherkin/i18n' 374: @out_stream.write(Gherkin::I18n.get(lang).keyword_table) 375: Kernel.exit(0) 376: end
# File lib/cucumber/cli/options.rb, line 378 378: def list_languages_and_exit 379: require 'gherkin/i18n' 380: @out_stream.write(Gherkin::I18n.language_table) 381: Kernel.exit(0) 382: end
# File lib/cucumber/cli/options.rb, line 317 317: def merge_profiles 318: if @disable_profile_loading 319: @out_stream.puts "Disabling profiles..." 320: return 321: end 322: 323: @profiles << @default_profile if default_profile_should_be_used? 324: 325: @profiles.each do |profile| 326: profile_args = profile_loader.args_from(profile) 327: reverse_merge( 328: Options.parse(profile_args, @out_stream, @error_stream, :skip_profile_information => true) 329: ) 330: end 331: end
# File lib/cucumber/cli/options.rb, line 296 296: def non_stdout_formats 297: @options[:formats].select {|format, output| output != @out_stream } 298: end
# File lib/cucumber/cli/options.rb, line 384 384: def print_profile_information 385: return if @skip_profile_information || @profiles.empty? 386: profiles_sentence = '' 387: profiles_sentence = @profiles.size == 1 ? @profiles.first : 388: "#{@profiles[0...-1].join(', ')} and #{@profiles.last}" 389: 390: @out_stream.puts "Using the #{profiles_sentence} profile#{'s' if @profiles.size> 1}..." 391: end
# File lib/cucumber/cli/options.rb, line 339 339: def profile_loader 340: @profile_loader ||= ProfileLoader.new 341: end
# File lib/cucumber/cli/options.rb, line 343 343: def reverse_merge(other_options) 344: @options = other_options.options.merge(@options) 345: @options[:require] += other_options[:require] 346: @options[:excludes] += other_options[:excludes] 347: @options[:name_regexps] += other_options[:name_regexps] 348: @options[:tag_expressions] += other_options[:tag_expressions] 349: @options[:env_vars] = other_options[:env_vars].merge(@options[:env_vars]) 350: if @options[:paths].empty? 351: @options[:paths] = other_options[:paths] 352: else 353: @overridden_paths += (other_options[:paths] - @options[:paths]) 354: end 355: @options[:source] &= other_options[:source] 356: @options[:snippets] &= other_options[:snippets] 357: @options[:strict] |= other_options[:strict] 358: 359: @profiles += other_options.profiles 360: @expanded_args += other_options.expanded_args 361: 362: if @options[:formats].empty? 363: @options[:formats] = other_options[:formats] 364: else 365: @options[:formats] += other_options[:formats] 366: @options[:formats] = stdout_formats[0..0] + non_stdout_formats 367: end 368: 369: self 370: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.