You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

configuration.rb 3.4 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # frozen_string_literal: true
  2. require 'logger'
  3. require 'cucumber/cli/options'
  4. require 'cucumber/cli/rerun_file'
  5. require 'cucumber/constantize'
  6. require 'cucumber'
  7. module Cucumber
  8. module Cli
  9. class YmlLoadError < StandardError; end
  10. class ProfilesNotDefinedError < YmlLoadError; end
  11. class ProfileNotFound < StandardError; end
  12. class Configuration
  13. include Constantize
  14. attr_reader :out_stream
  15. def initialize(out_stream = $stdout, error_stream = $stderr)
  16. @out_stream = out_stream
  17. @error_stream = error_stream
  18. @options = Options.new(@out_stream, @error_stream, default_profile: 'default')
  19. end
  20. def parse!(args)
  21. @args = args
  22. @options.parse!(args)
  23. arrange_formats
  24. raise("You can't use both --strict and --wip") if strict.strict? && wip?
  25. set_environment_variables
  26. end
  27. def verbose?
  28. @options[:verbose]
  29. end
  30. def randomize?
  31. @options[:order] == 'random'
  32. end
  33. def seed
  34. Integer(@options[:seed] || rand(0xFFFF))
  35. end
  36. def strict
  37. @options[:strict]
  38. end
  39. def wip?
  40. @options[:wip]
  41. end
  42. def guess?
  43. @options[:guess]
  44. end
  45. def dry_run?
  46. @options[:dry_run]
  47. end
  48. def expand?
  49. @options[:expand]
  50. end
  51. def fail_fast?
  52. @options[:fail_fast]
  53. end
  54. def retry_attempts
  55. @options[:retry]
  56. end
  57. def snippet_type
  58. @options[:snippet_type] || :cucumber_expression
  59. end
  60. def log
  61. logger = Logger.new(@out_stream)
  62. logger.formatter = LogFormatter.new
  63. logger.level = Logger::INFO
  64. logger.level = Logger::DEBUG if verbose?
  65. logger
  66. end
  67. def tag_limits
  68. @options[:tag_limits]
  69. end
  70. def tag_expressions
  71. @options[:tag_expressions]
  72. end
  73. def name_regexps
  74. @options[:name_regexps]
  75. end
  76. def filters
  77. @options.filters
  78. end
  79. def formats
  80. @options[:formats]
  81. end
  82. def paths
  83. @options[:paths]
  84. end
  85. def to_hash
  86. Hash(@options).merge(out_stream: @out_stream, error_stream: @error_stream, seed: seed)
  87. end
  88. private
  89. class LogFormatter < ::Logger::Formatter
  90. def call(_severity, _time, _progname, msg)
  91. msg
  92. end
  93. end
  94. def set_environment_variables
  95. @options[:env_vars].each do |var, value|
  96. ENV[var] = value
  97. end
  98. end
  99. def arrange_formats
  100. add_default_formatter if needs_default_formatter?
  101. @options[:formats] = @options[:formats].sort_by do |f|
  102. f[2] == @out_stream ? -1 : 1
  103. end
  104. @options[:formats].uniq!
  105. @options.check_formatter_stream_conflicts
  106. end
  107. def add_default_formatter
  108. @options[:formats] << ['pretty', {}, @out_stream]
  109. end
  110. def needs_default_formatter?
  111. formatter_missing? || publish_only?
  112. end
  113. def formatter_missing?
  114. @options[:formats].empty?
  115. end
  116. def publish_only?
  117. @options[:formats]
  118. .uniq
  119. .map { |formatter, _, stream| [formatter, stream] }
  120. .uniq
  121. .reject { |formatter, stream| formatter == 'message' && stream != @out_stream }
  122. .empty?
  123. end
  124. end
  125. end
  126. end

No Description

Contributors (1)