class Cucumber::Cli::Options
Constants
- BUILTIN_FORMATS
- CUCUMBER_PUBLISH_URL
- FAIL_FAST_FLAG
- FORMAT_HELP
- FORMAT_HELP_MSG
- INDENT
- NO_PROFILE_LONG_FLAG
- NO_PROFILE_SHORT_FLAG
- OPTIONS_WITH_ARGS
- ORDER_TYPES
- PROFILE_LONG_FLAG
- PROFILE_SHORT_FLAG
- RETRY_FLAG
- RETRY_TOTAL_FLAG
- TAG_LIMIT_MATCHER
Attributes
Public Class Methods
Source
# File lib/cucumber/cli/options.rb, line 72 def initialize(out_stream = $stdout, error_stream = $stderr, options = {}) @out_stream = out_stream @error_stream = error_stream @default_profile = options[:default_profile] @profiles = options[:profiles] || [] @overridden_paths = [] @options = default_options.merge(options) @profile_loader = options[:profile_loader] @options[:skip_profile_information] = options[:skip_profile_information] @disable_profile_loading = nil end
Source
# File lib/cucumber/cli/options.rb, line 68 def self.parse(args, out_stream, error_stream, options = {}) new(out_stream, error_stream, options).parse!(args) end
Public Instance Methods
Source
# File lib/cucumber/cli/options.rb, line 90 def []=(key, value) @options[key] = value end
Source
# File lib/cucumber/cli/options.rb, line 182 def check_formatter_stream_conflicts streams = @options[:formats].uniq.map { |(_, _, stream)| stream } return if streams == streams.uniq raise 'All but one formatter must use --out, only one can print to each stream (or STDOUT)' end
Source
# File lib/cucumber/cli/options.rb, line 174 def custom_profiles @profiles - [@default_profile] end
Source
# File lib/cucumber/cli/options.rb, line 178 def filters @options[:filters] ||= [] end
Source
# File lib/cucumber/cli/options.rb, line 94 def parse!(args) @args = args @expanded_args = @args.dup @args.extend(::OptionParser::Arguable) @args.options do |opts| opts.banner = banner opts.on('--publish', 'Publish a report to https://reports.cucumber.io') do set_option :publish_enabled, true end opts.on('--publish-quiet', 'Don\'t print information banner about publishing reports') { set_option :publish_quiet } opts.on('-r LIBRARY|DIR', '--require LIBRARY|DIR', *require_files_msg) { |lib| require_files(lib) } opts.on('-j DIR', '--jars DIR', 'Load all the jars under DIR') { |jars| load_jars(jars) } if Cucumber::JRUBY opts.on("#{RETRY_FLAG} ATTEMPTS", *retry_msg) { |v| set_option :retry, v.to_i } opts.on("#{RETRY_TOTAL_FLAG} TESTS", *retry_total_msg) { |v| set_option :retry_total, v.to_i } opts.on('--i18n-languages', *i18n_languages_msg) { list_languages_and_exit } opts.on('--i18n-keywords LANG', *i18n_keywords_msg) { |lang| language lang } opts.on(FAIL_FAST_FLAG, 'Exit immediately following the first failing scenario') { set_option :fail_fast } opts.on('-f FORMAT', '--format FORMAT', *format_msg, *FORMAT_HELP) do |v| add_option :formats, [*parse_formats(v), @out_stream] end opts.on('--init', *init_msg) { initialize_project } opts.on('-o', '--out [FILE|DIR|URL]', *out_msg) { |v| out_stream v } opts.on('-t TAG_EXPRESSION', '--tags TAG_EXPRESSION', *tags_msg) { |v| add_tag(v) } opts.on('-n NAME', '--name NAME', *name_msg) { |v| add_option(:name_regexps, /#{v}/) } opts.on('-e', '--exclude PATTERN', *exclude_msg) { |v| add_option :excludes, Regexp.new(v) } opts.on(PROFILE_SHORT_FLAG, "#{PROFILE_LONG_FLAG} PROFILE", *profile_short_flag_msg) { |v| add_profile v } opts.on(NO_PROFILE_SHORT_FLAG, NO_PROFILE_LONG_FLAG, *no_profile_short_flag_msg) { |_v| disable_profile_loading } opts.on('-c', '--[no-]color', *color_msg) { |v| color v } opts.on('-d', '--dry-run', *dry_run_msg) { set_dry_run_and_duration } opts.on('-m', '--no-multiline', "Don't print multiline strings and tables under steps.") { set_option :no_multiline } opts.on('-s', '--no-source', "Don't print the file and line of the step definition with the steps.") { set_option :source, false } opts.on('-i', '--no-snippets', "Don't print snippets for pending steps.") { set_option :snippets, false } opts.on('-I', '--snippet-type TYPE', *snippet_type_msg) { |v| set_option :snippet_type, v.to_sym } opts.on('-q', '--quiet', 'Alias for --no-snippets --no-source --no-duration --publish-quiet.') { shut_up } opts.on('--no-duration', "Don't print the duration at the end of the summary") { set_option :duration, false } opts.on('-b', '--backtrace', 'Show full backtrace for all errors.') { Cucumber.use_full_backtrace = true } opts.on('-S', '--[no-]strict', *strict_msg) { |setting| set_strict(setting) } opts.on('--[no-]strict-undefined', 'Fail if there are any undefined results.') { |setting| set_strict(setting, :undefined) } opts.on('--[no-]strict-pending', 'Fail if there are any pending results.') { |setting| set_strict(setting, :pending) } opts.on('--[no-]strict-flaky', 'Fail if there are any flaky results.') { |setting| set_strict(setting, :flaky) } opts.on('-w', '--wip', 'Fail if there are any passing scenarios.') { set_option :wip } opts.on('-v', '--verbose', 'Show the files and features loaded.') { set_option :verbose } opts.on('-g', '--guess', 'Guess best match for Ambiguous steps.') { set_option :guess } opts.on('-l', '--lines LINES', *lines_msg) { |lines| set_option :lines, lines } opts.on('-x', '--expand', 'Expand Scenario Outline Tables in output.') { set_option :expand } opts.on('--order TYPE[:SEED]', 'Run examples in the specified order. Available types:', *<<~TEXT.split("\n")) do |order| [defined] Run scenarios in the order they were defined (default). [random] Shuffle scenarios before running. [reverse] Run scenarios in the opposite order to which they were defined. Specify SEED to reproduce the shuffling from a previous run. e.g. --order random:5738 TEXT @options[:order], @options[:seed] = *order.split(':') raise "'#{@options[:order]}' is not a recognised order type. Please use one of #{ORDER_TYPES.join(', ')}." unless ORDER_TYPES.include?(@options[:order]) end opts.on_tail('--version', 'Show version.') { exit_ok(Cucumber::VERSION) } opts.on_tail('-h', '--help', "You're looking at it.") { exit_ok(opts.help) } end.parse! process_publish_options @args.map! { |a| "#{a}:#{@options[:lines]}" } if @options[:lines] extract_environment_variables @options[:paths] = @args.dup # whatver is left over check_formatter_stream_conflicts merge_profiles self end
Private Instance Methods
Source
# File lib/cucumber/cli/options.rb, line 412 def add_option(option, value) @options[option] << value end
Source
# File lib/cucumber/cli/options.rb, line 444 def add_profile(profile) @profiles << profile end
Source
# File lib/cucumber/cli/options.rb, line 416 def add_tag(value) raise("Found tags option '#{value}'. '~@tag' is no longer supported, use 'not @tag' instead.") if value.include?('~') raise("Found tags option '#{value}'. '@tag1,@tag2' is no longer supported, use '@tag or @tag2' instead.") if value.include?(',') @options[:tag_expressions] << value.gsub(/(@\w+)(:\d+)?/, '\1') add_tag_limits(value) end
Source
# File lib/cucumber/cli/options.rb, line 430 def add_tag_limit(tag_limits, tag_name, limit) raise "Inconsistent tag limits for #{tag_name}: #{tag_limits[tag_name]} and #{limit}" if tag_limits[tag_name] && tag_limits[tag_name] != limit tag_limits[tag_name] = limit end
Source
# File lib/cucumber/cli/options.rb, line 424 def add_tag_limits(value) value.split(/[, ]/).map { |part| TAG_LIMIT_MATCHER.match(part) }.compact.each do |matchdata| add_tag_limit(@options[:tag_limits], matchdata[:tag_name], matchdata[:limit].to_i) end end
Source
# File lib/cucumber/cli/options.rb, line 436 def color(color) Cucumber::Term::ANSIColor.coloring = color end
Source
# File lib/cucumber/cli/options.rb, line 213 def color_msg [ 'Whether or not to use ANSI color in the output. Cucumber decides', 'based on your platform and the output destination if not specified.' ] end
Source
# File lib/cucumber/cli/options.rb, line 603 def default_options Cucumber::Configuration.default_options end
Source
# File lib/cucumber/cli/options.rb, line 504 def default_profile_should_be_used? @profiles.empty? && profile_loader.cucumber_yml_defined? && profile_loader.profile?(@default_profile) end
Source
# File lib/cucumber/cli/options.rb, line 404 def disable_profile_loading @disable_profile_loading = true end
Source
# File lib/cucumber/cli/options.rb, line 220 def dry_run_msg ['Invokes formatters without executing the steps.'] end
Source
# File lib/cucumber/cli/options.rb, line 224 def exclude_msg ["Don't run feature files or require ruby files matching PATTERN"] end
Source
# File lib/cucumber/cli/options.rb, line 457 def exit_ok(text) @out_stream.puts(text) Kernel.exit(0) end
Source
# File lib/cucumber/cli/options.rb, line 477 def extract_environment_variables @args.delete_if do |arg| if arg =~ /^(\w+)=(.*)$/ @options[:env_vars][Regexp.last_match(1)] = Regexp.last_match(2) true end end end
Source
# File lib/cucumber/cli/options.rb, line 228 def format_msg ['How to format features (Default: pretty). Available formats:'] end
Source
# File lib/cucumber/cli/options.rb, line 238 def i18n_keywords_msg [ 'List keywords for in a particular language', %(Run with "--i18n help" to see all languages) ] end
Source
# File lib/cucumber/cli/options.rb, line 232 def i18n_languages_msg [ 'List all available languages' ] end
Source
# File lib/cucumber/cli/options.rb, line 553 def indicate_invalid_language_and_exit(lang) @out_stream.write("Invalid language '#{lang}'. Available languages are:\n") list_languages_and_exit end
Source
# File lib/cucumber/cli/options.rb, line 245 def init_msg [ 'Initializes folder structure and generates conventional files for', 'a Cucumber project.' ] end
Source
# File lib/cucumber/cli/options.rb, line 440 def initialize_project ProjectInitializer.new.run && Kernel.exit(0) end
Source
# File lib/cucumber/cli/options.rb, line 396 def language(lang) require 'gherkin/dialect' return indicate_invalid_language_and_exit(lang) unless ::Gherkin::DIALECTS.key?(lang) list_keywords_and_exit(lang) end
Source
# File lib/cucumber/cli/options.rb, line 252 def lines_msg ['Run given line numbers. Equivalent to FILE:LINE syntax'] end
Source
# File lib/cucumber/cli/options.rb, line 558 def list_keywords_and_exit(lang) require 'gherkin/dialect' language = ::Gherkin::Dialect.for(lang) data = Cucumber::MultilineArgument::DataTable.from( [ ['feature', to_keywords_string(language.feature_keywords)], ['background', to_keywords_string(language.background_keywords)], ['scenario', to_keywords_string(language.scenario_keywords)], ['scenario_outline', to_keywords_string(language.scenario_outline_keywords)], ['examples', to_keywords_string(language.examples_keywords)], ['given', to_keywords_string(language.given_keywords)], ['when', to_keywords_string(language.when_keywords)], ['then', to_keywords_string(language.then_keywords)], ['and', to_keywords_string(language.and_keywords)], ['but', to_keywords_string(language.but_keywords)], ['given (code)', to_code_keywords_string(language.given_keywords)], ['when (code)', to_code_keywords_string(language.when_keywords)], ['then (code)', to_code_keywords_string(language.then_keywords)], ['and (code)', to_code_keywords_string(language.and_keywords)], ['but (code)', to_code_keywords_string(language.but_keywords)] ] ) @out_stream.write(data.to_s(color: false, prefixes: Hash.new(''))) Kernel.exit(0) end
Source
# File lib/cucumber/cli/options.rb, line 584 def list_languages_and_exit require 'gherkin/dialect' data = Cucumber::MultilineArgument::DataTable.from( ::Gherkin::DIALECTS.keys.map do |key| [key, ::Gherkin::DIALECTS[key].fetch('name'), ::Gherkin::DIALECTS[key].fetch('native')] end ) @out_stream.write(data.to_s(color: false, prefixes: Hash.new(''))) Kernel.exit(0) end
Source
# File lib/cucumber/cli/options.rb, line 486 def merge_profiles return @out_stream.puts 'Disabling profiles...' if @disable_profile_loading @profiles << @default_profile if default_profile_should_be_used? @profiles.each { |profile| merge_with_profile(profile) } @options[:profiles] = @profiles end
Source
# File lib/cucumber/cli/options.rb, line 549 def merge_tag_limits(option_limits, other_limits) other_limits.each { |key, value| add_tag_limit(option_limits, key, value) } end
Source
# File lib/cucumber/cli/options.rb, line 494 def merge_with_profile(profile) profile_args = profile_loader.args_from(profile) profile_options = Options.parse( profile_args, @out_stream, @error_stream, skip_profile_information: true, profile_loader: profile_loader ) reverse_merge(profile_options) end
Source
# File lib/cucumber/cli/options.rb, line 283 def name_msg [ 'Only execute the feature elements which match part of the given name.', 'If this option is given more than once, it will match against all the', 'given names.' ] end
Source
# File lib/cucumber/cli/options.rb, line 256 def no_profile_short_flag_msg [ "Disables all profile loading to avoid using the 'default' profile." ] end
Source
# File lib/cucumber/cli/options.rb, line 408 def non_stdout_formats @options[:formats].reject { |_, _, output| output == @out_stream } end
Source
# File lib/cucumber/cli/options.rb, line 332 def out_msg [ 'Write output to a file/directory/URL instead of STDOUT. This option', 'applies to the previously specified --format, or the', 'default format if no format is specified. Check the specific', "formatter's docs to see whether to pass a file, dir or URL.", "\n", 'When using a URL, the output of the formatter will be sent as the HTTP request body.', 'HTTP headers and request method can be set with cURL like options.', 'Example: --out "http://example.com -X POST -H Content-Type:text/json"' ] end
Source
# File lib/cucumber/cli/options.rb, line 304 def out_stream(value) @options[:formats] << ['pretty', {}, nil] if @options[:formats].empty? @options[:formats][-1][2] = value end
Source
# File lib/cucumber/cli/options.rb, line 298 def parse_formats(value) formatter, *formatter_options = value.split(',') options_hash = Hash[formatter_options.map { |string| string.split('=') }] [formatter, options_hash] end
Source
# File lib/cucumber/cli/options.rb, line 200 def process_publish_options @options[:publish_enabled] = true if truthy_string?(ENV['CUCUMBER_PUBLISH_ENABLED']) || ENV['CUCUMBER_PUBLISH_TOKEN'] @options[:formats] << publisher if @options[:publish_enabled] @options[:publish_quiet] = true if truthy_string?(ENV['CUCUMBER_PUBLISH_QUIET']) end
Source
# File lib/cucumber/cli/options.rb, line 510 def profile_loader @profile_loader ||= ProfileLoader.new end
Source
# File lib/cucumber/cli/options.rb, line 262 def profile_short_flag_msg [ 'Pull commandline arguments from cucumber.yml which can be defined as', "strings or arrays. When a 'default' profile is defined and no profile", 'is specified it is always used. (Unless disabled, see -P below.)', 'When feature files are defined in a profile and on the command line', 'then only the ones from the command line are used.' ] end
Source
# File lib/cucumber/cli/options.rb, line 390 def publisher url = CUCUMBER_PUBLISH_URL url += %( -H "Authorization: Bearer #{ENV['CUCUMBER_PUBLISH_TOKEN']}") if ENV['CUCUMBER_PUBLISH_TOKEN'] ['message', {}, url] end
Source
# File lib/cucumber/cli/options.rb, line 378 def require_files(filenames) @options[:require] << filenames return unless Cucumber::JRUBY && File.directory?(filenames) require 'java' $CLASSPATH << filenames end
Source
# File lib/cucumber/cli/options.rb, line 345 def require_files_msg [ 'Require files before executing the features. If this', 'option is not specified, all *.rb files that are', 'siblings of or below the features will be loaded auto-', 'matically. Automatic loading is disabled when this', 'option is specified; all loading becomes explicit.', 'Files in directories named "support" are still always', 'loaded first when their parent directories are', 'required or if the "support" directories themselves are', 'explicitly required.', 'This option can be specified multiple times.' ] end
Source
# File lib/cucumber/cli/options.rb, line 386 def require_jars(jars) Dir["#{jars}/**/*.jar"].sort.each { |jar| require jar } end
Source
# File lib/cucumber/cli/options.rb, line 272 def retry_msg ['Specify the number of times to retry failing tests (default: 0)'] end
Source
# File lib/cucumber/cli/options.rb, line 276 def retry_total_msg [ 'The total number of failing test after which retrying of tests is suspended.', 'Example: --retry-total 10 -> Will stop retrying tests after 10 failing tests.' ] end
Source
# File lib/cucumber/cli/options.rb, line 514 def reverse_merge(other_options) @options = other_options.options.merge(@options) @options[:require] += other_options[:require] @options[:excludes] += other_options[:excludes] @options[:name_regexps] += other_options[:name_regexps] @options[:tag_expressions] += other_options[:tag_expressions] merge_tag_limits(@options[:tag_limits], other_options[:tag_limits]) @options[:env_vars] = other_options[:env_vars].merge(@options[:env_vars]) if @options[:paths].empty? @options[:paths] = other_options[:paths] else @overridden_paths += (other_options[:paths] - @options[:paths]) end @options[:source] &= other_options[:source] @options[:snippets] &= other_options[:snippets] @options[:duration] &= other_options[:duration] @options[:strict] = other_options[:strict].merge!(@options[:strict]) @options[:dry_run] |= other_options[:dry_run] @profiles += other_options.profiles @expanded_args += other_options.expanded_args if @options[:formats].empty? @options[:formats] = other_options[:formats] else @options[:formats] += other_options[:formats] @options[:formats] = stdout_formats[0..0] + non_stdout_formats end @options[:retry] = other_options[:retry] if @options[:retry].zero? @options[:retry_total] = other_options[:retry_total] if @options[:retry_total].infinite? self end
Source
# File lib/cucumber/cli/options.rb, line 452 def set_dry_run_and_duration @options[:dry_run] = true @options[:duration] = false end
Source
# File lib/cucumber/cli/options.rb, line 448 def set_option(option, value = nil) @options[option] = value.nil? ? true : value end
Source
# File lib/cucumber/cli/options.rb, line 469 def set_strict(setting, type = nil) @options[:strict].set_strict(setting, type) end
Source
# File lib/cucumber/cli/options.rb, line 462 def shut_up @options[:publish_quiet] = true @options[:snippets] = false @options[:source] = false @options[:duration] = false end
Source
# File lib/cucumber/cli/options.rb, line 360 def snippet_type_msg [ 'Use different snippet type (Default: cucumber_expression). Available types:', Cucumber::Glue::RegistryAndMore.cli_snippet_type_options ].flatten end
Source
# File lib/cucumber/cli/options.rb, line 473 def stdout_formats @options[:formats].select { |_, _, output| output == @out_stream } end
Source
# File lib/cucumber/cli/options.rb, line 291 def strict_msg [ 'Fail if there are any strict affected results ', '(that is undefined, pending or flaky results).' ] end
Source
# File lib/cucumber/cli/options.rb, line 599 def to_code_keywords_string(list) to_keywords_string(Cucumber::Gherkin::I18n.code_keywords_for(list)) end
Source
# File lib/cucumber/cli/options.rb, line 595 def to_keywords_string(list) list.map { |item| "\"#{item}\"" }.join(', ') end
Source
# File lib/cucumber/cli/options.rb, line 207 def truthy_string?(str) return false if str.nil? str !~ /^(false|no|0)$/i end