cucumber 7.1.0 → 9.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -27
  3. data/VERSION +1 -0
  4. data/lib/cucumber/cli/configuration.rb +4 -1
  5. data/lib/cucumber/cli/main.rb +5 -4
  6. data/lib/cucumber/cli/options.rb +73 -67
  7. data/lib/cucumber/cli/profile_loader.rb +6 -10
  8. data/lib/cucumber/cli/rerun_file.rb +1 -1
  9. data/lib/cucumber/configuration.rb +12 -6
  10. data/lib/cucumber/constantize.rb +1 -1
  11. data/lib/cucumber/deprecate.rb +6 -46
  12. data/lib/cucumber/errors.rb +3 -2
  13. data/lib/cucumber/events/envelope.rb +2 -0
  14. data/lib/cucumber/events/gherkin_source_parsed.rb +2 -0
  15. data/lib/cucumber/events/gherkin_source_read.rb +2 -0
  16. data/lib/cucumber/events/hook_test_step_created.rb +1 -2
  17. data/lib/cucumber/events/step_activated.rb +0 -6
  18. data/lib/cucumber/events/step_definition_registered.rb +0 -5
  19. data/lib/cucumber/events/test_case_created.rb +1 -2
  20. data/lib/cucumber/events/test_case_finished.rb +2 -0
  21. data/lib/cucumber/events/test_case_started.rb +2 -0
  22. data/lib/cucumber/events/test_run_finished.rb +2 -1
  23. data/lib/cucumber/events/test_step_created.rb +1 -2
  24. data/lib/cucumber/events/test_step_finished.rb +2 -0
  25. data/lib/cucumber/events/test_step_started.rb +2 -0
  26. data/lib/cucumber/events/undefined_parameter_type.rb +3 -2
  27. data/lib/cucumber/events.rb +1 -1
  28. data/lib/cucumber/file_specs.rb +2 -1
  29. data/lib/cucumber/filters/activate_steps.rb +1 -0
  30. data/lib/cucumber/filters/retry.rb +20 -1
  31. data/lib/cucumber/filters/tag_limits/verifier.rb +1 -3
  32. data/lib/cucumber/filters/tag_limits.rb +1 -3
  33. data/lib/cucumber/formatter/ansicolor.rb +70 -78
  34. data/lib/cucumber/formatter/ast_lookup.rb +16 -8
  35. data/lib/cucumber/formatter/backtrace_filter.rb +2 -1
  36. data/lib/cucumber/formatter/console.rb +26 -16
  37. data/lib/cucumber/formatter/console_counts.rb +3 -1
  38. data/lib/cucumber/formatter/console_issues.rb +10 -3
  39. data/lib/cucumber/formatter/curl_option_parser.rb +49 -0
  40. data/lib/cucumber/formatter/duration_extractor.rb +1 -0
  41. data/lib/cucumber/formatter/errors.rb +3 -0
  42. data/lib/cucumber/formatter/fail_fast.rb +1 -1
  43. data/lib/cucumber/formatter/fanout.rb +1 -1
  44. data/lib/cucumber/formatter/html.rb +2 -0
  45. data/lib/cucumber/formatter/http_io.rb +10 -137
  46. data/lib/cucumber/formatter/ignore_missing_messages.rb +1 -1
  47. data/lib/cucumber/formatter/io.rb +5 -3
  48. data/lib/cucumber/formatter/io_http_buffer.rb +88 -0
  49. data/lib/cucumber/formatter/json.rb +10 -12
  50. data/lib/cucumber/formatter/junit.rb +10 -7
  51. data/lib/cucumber/formatter/message_builder.rb +24 -8
  52. data/lib/cucumber/formatter/pretty.rb +24 -10
  53. data/lib/cucumber/formatter/progress.rb +1 -0
  54. data/lib/cucumber/formatter/publish_banner_printer.rb +0 -2
  55. data/lib/cucumber/formatter/query/hook_by_test_step.rb +3 -0
  56. data/lib/cucumber/formatter/query/pickle_by_test.rb +2 -0
  57. data/lib/cucumber/formatter/query/pickle_step_by_test_step.rb +2 -0
  58. data/lib/cucumber/formatter/query/step_definitions_by_test_step.rb +2 -0
  59. data/lib/cucumber/formatter/query/test_case_started_by_test_case.rb +4 -0
  60. data/lib/cucumber/formatter/rerun.rb +5 -3
  61. data/lib/cucumber/formatter/summary.rb +1 -0
  62. data/lib/cucumber/formatter/unicode.rb +7 -7
  63. data/lib/cucumber/formatter/url_reporter.rb +3 -1
  64. data/lib/cucumber/formatter/usage.rb +3 -3
  65. data/lib/cucumber/gherkin/data_table_parser.rb +1 -0
  66. data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +25 -27
  67. data/lib/cucumber/glue/dsl.rb +20 -25
  68. data/lib/cucumber/glue/hook.rb +6 -3
  69. data/lib/cucumber/glue/invoke_in_world.rb +5 -5
  70. data/lib/cucumber/glue/proto_world.rb +30 -34
  71. data/lib/cucumber/glue/registry_and_more.rb +15 -25
  72. data/lib/cucumber/glue/snippet.rb +4 -2
  73. data/lib/cucumber/glue/step_definition.rb +6 -3
  74. data/lib/cucumber/glue/world_factory.rb +2 -0
  75. data/lib/cucumber/hooks.rb +1 -0
  76. data/lib/cucumber/multiline_argument/data_table/diff_matrices.rb +4 -1
  77. data/lib/cucumber/multiline_argument/data_table.rb +68 -80
  78. data/lib/cucumber/platform.rb +11 -16
  79. data/lib/cucumber/rake/task.rb +22 -15
  80. data/lib/cucumber/rspec/disable_option_parser.rb +6 -3
  81. data/lib/cucumber/running_test_case.rb +2 -1
  82. data/lib/cucumber/runtime/for_programming_languages.rb +1 -2
  83. data/lib/cucumber/runtime/meta_message_builder.rb +108 -0
  84. data/lib/cucumber/runtime/support_code.rb +3 -0
  85. data/lib/cucumber/runtime/user_interface.rb +7 -6
  86. data/lib/cucumber/runtime.rb +22 -38
  87. data/lib/cucumber/step_match.rb +6 -4
  88. data/lib/cucumber/step_match_search.rb +3 -2
  89. data/lib/cucumber/term/ansicolor.rb +74 -50
  90. data/lib/cucumber/term/banner.rb +3 -0
  91. data/lib/cucumber.rb +2 -1
  92. data/lib/simplecov_setup.rb +1 -1
  93. metadata +95 -244
  94. data/CHANGELOG.md +0 -3131
  95. data/CONTRIBUTING.md +0 -250
  96. data/lib/autotest/cucumber.rb +0 -8
  97. data/lib/autotest/cucumber_mixin.rb +0 -130
  98. data/lib/autotest/cucumber_rails.rb +0 -8
  99. data/lib/autotest/cucumber_rails_rspec.rb +0 -8
  100. data/lib/autotest/cucumber_rails_rspec2.rb +0 -8
  101. data/lib/autotest/cucumber_rspec.rb +0 -8
  102. data/lib/autotest/cucumber_rspec2.rb +0 -8
  103. data/lib/autotest/discover.rb +0 -13
  104. data/lib/cucumber/version +0 -1
@@ -4,51 +4,11 @@ require 'cucumber/platform'
4
4
  require 'cucumber/gherkin/formatter/ansi_escapes'
5
5
 
6
6
  module Cucumber
7
- module Deprecate
8
- class AnsiString
9
- include Cucumber::Gherkin::Formatter::AnsiEscapes
10
-
11
- def self.failure_message(message)
12
- AnsiString.new.failure_message(message)
13
- end
14
-
15
- def failure_message(message)
16
- failed + message + reset
17
- end
18
- end
19
-
20
- class CliOption
21
- def self.deprecate(stream, option, message, remove_after_version)
22
- return if stream.nil?
23
- stream.puts(
24
- AnsiString.failure_message(
25
- "\nWARNING: #{option} is deprecated" \
26
- " and will be removed after version #{remove_after_version}.\n#{message}.\n"
27
- )
28
- )
29
- end
30
- end
31
-
32
- module ForUsers
33
- def self.call(message, method, remove_after_version)
34
- STDERR.puts AnsiString.failure_message(
35
- "\nWARNING: ##{method} is deprecated" \
36
- " and will be removed after version #{remove_after_version}. #{message}.\n" \
37
- "(Called from #{caller(3..3).first})"
38
- )
39
- end
40
- end
41
-
42
- module ForDevelopers
43
- def self.call(_message, _method, remove_after_version)
44
- raise "This method is due for removal after version #{remove_after_version}" if Cucumber::VERSION >= remove_after_version
45
- end
46
- end
47
-
48
- STRATEGY = $PROGRAM_NAME =~ /rspec$/ ? ForDevelopers : ForUsers
49
- end
50
-
51
- def self.deprecate(*args)
52
- Deprecate::STRATEGY.call(*args)
7
+ def self.deprecate(message, method, remove_after_version)
8
+ $stderr.puts(
9
+ "\nWARNING: ##{method} is deprecated" \
10
+ " and will be removed after version #{remove_after_version}. #{message}.\n" \
11
+ "(Called from #{caller(3..3).first})"
12
+ )
53
13
  end
54
14
  end
@@ -9,7 +9,7 @@ module Cucumber
9
9
  return result.with_message(with_prefix(result.message)) if result.is_a?(self)
10
10
 
11
11
  begin
12
- raise new(with_prefix(step_name)) # rubocop:disable Style/RaiseArgs
12
+ raise self, with_prefix(step_name)
13
13
  rescue StandardError => e
14
14
  e
15
15
  end
@@ -35,7 +35,8 @@ module Cucumber
35
35
  # Raised when a step matches 2 or more StepDefinitions
36
36
  class Ambiguous < StandardError
37
37
  def initialize(step_name, step_definitions, used_guess)
38
- message = String.new # rubocop:disable Style/EmptyLiteral
38
+ # TODO: [LH] - Just use a heredoc here to fix this up
39
+ message = String.new
39
40
  message << "Ambiguous match of \"#{step_name}\":\n\n"
40
41
  message << step_definitions.map(&:backtrace_line).join("\n")
41
42
  message << "\n\n"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -6,8 +6,7 @@ module Cucumber
6
6
  module Events
7
7
  # Event fired when a step is created from a hook
8
8
  class HookTestStepCreated < Core::Event.new(:test_step, :hook)
9
- attr_reader :test_step
10
- attr_reader :hook
9
+ attr_reader :test_step, :hook
11
10
  end
12
11
  end
13
12
  end
@@ -15,12 +15,6 @@ module Cucumber
15
15
  #
16
16
  # @return [Cucumber::StepMatch]
17
17
  attr_reader :step_match
18
-
19
- # @private
20
- def initialize(test_step, step_match)
21
- @test_step = test_step
22
- @step_match = step_match
23
- end
24
18
  end
25
19
  end
26
20
  end
@@ -10,11 +10,6 @@ module Cucumber
10
10
  #
11
11
  # @return [RbSupport::RbStepDefinition]
12
12
  attr_reader :step_definition
13
-
14
- # _@private
15
- def initialize(step_definition)
16
- @step_definition = step_definition
17
- end
18
13
  end
19
14
  end
20
15
  end
@@ -6,8 +6,7 @@ module Cucumber
6
6
  module Events
7
7
  # Event fired when a Test::Case is created from a Pickle
8
8
  class TestCaseCreated < Core::Event.new(:test_case, :pickle)
9
- attr_reader :test_case
10
- attr_reader :pickle
9
+ attr_reader :test_case, :pickle
11
10
  end
12
11
  end
13
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -5,7 +5,8 @@ require 'cucumber/core/events'
5
5
  module Cucumber
6
6
  module Events
7
7
  # Event fired after all test cases have finished executing
8
- class TestRunFinished < Core::Event.new
8
+ class TestRunFinished < Core::Event.new(:success)
9
+ attr_reader :success
9
10
  end
10
11
  end
11
12
  end
@@ -6,8 +6,7 @@ module Cucumber
6
6
  module Events
7
7
  # Event fired when a TestStep is created from a PickleStep
8
8
  class TestStepCreated < Core::Event.new(:test_step, :pickle_step)
9
- attr_reader :test_step
10
- attr_reader :pickle_step
9
+ attr_reader :test_step, :pickle_step
11
10
  end
12
11
  end
13
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/core/events'
2
4
 
3
5
  module Cucumber
4
6
  module Events
5
7
  class UndefinedParameterType < Core::Event.new(:type_name, :expression)
6
- attr_reader :type_name
7
- attr_reader :expression
8
+ attr_reader :type_name, :expression
8
9
  end
9
10
  end
10
11
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir[File.dirname(__FILE__) + '/events/*.rb'].map(&method(:require))
3
+ Dir["#{File.dirname(__FILE__)}/events/*.rb"].map(&method(:require))
4
4
 
5
5
  module Cucumber
6
6
  # Events tell you what's happening while Cucumber runs your features.
@@ -5,7 +5,7 @@ require 'cucumber/core/test/location'
5
5
 
6
6
  module Cucumber
7
7
  class FileSpecs
8
- FILE_COLON_LINE_PATTERN = /^([\w\W]*?)(?::([\d:]+))?$/ #:nodoc:
8
+ FILE_COLON_LINE_PATTERN = /^([\w\W]*?)(?::([\d:]+))?$/.freeze # :nodoc:
9
9
 
10
10
  def initialize(file_specs)
11
11
  Cucumber.logger.debug("Features:\n")
@@ -32,6 +32,7 @@ module Cucumber
32
32
 
33
33
  def locations
34
34
  return [Core::Test::Location.new(@file)] if @lines.empty?
35
+
35
36
  @lines.map { |line| Core::Test::Location.new(@file, line) }
36
37
  end
37
38
  end
@@ -52,6 +52,7 @@ module Cucumber
52
52
  end
53
53
  configuration.notify :step_activated, test_step, match
54
54
  return SkippingStepMatch.new if configuration.dry_run?
55
+
55
56
  match
56
57
  end
57
58
 
@@ -7,6 +7,11 @@ require 'cucumber/events'
7
7
  module Cucumber
8
8
  module Filters
9
9
  class Retry < Core::Filter.new(:configuration)
10
+ def initialize(*_args)
11
+ super
12
+ @total_permanently_failed = 0
13
+ end
14
+
10
15
  def test_case(test_case)
11
16
  configuration.on_event(:test_case_finished) do |event|
12
17
  next unless retry_required?(test_case, event)
@@ -21,7 +26,21 @@ module Cucumber
21
26
  private
22
27
 
23
28
  def retry_required?(test_case, event)
24
- event.test_case == test_case && event.result.failed? && test_case_counts[test_case] < configuration.retry_attempts
29
+ return false unless event.test_case == test_case
30
+
31
+ return false unless event.result.failed?
32
+
33
+ return false if @total_permanently_failed >= configuration.retry_total_tests
34
+
35
+ retry_required = test_case_counts[test_case] < configuration.retry_attempts
36
+ if retry_required
37
+ # retry test
38
+ true
39
+ else
40
+ # test failed after max. attempts
41
+ @total_permanently_failed += 1
42
+ false
43
+ end
25
44
  end
26
45
 
27
46
  def test_case_counts
@@ -47,9 +47,7 @@ module Cucumber
47
47
  locations.count
48
48
  end
49
49
 
50
- attr_reader :tag_name
51
- attr_reader :limit
52
- attr_reader :locations
50
+ attr_reader :tag_name, :limit, :locations
53
51
  end
54
52
  end
55
53
  end
@@ -38,9 +38,7 @@ module Cucumber
38
38
 
39
39
  private
40
40
 
41
- attr_reader :gated_receiver
42
- attr_reader :test_case_index
43
- attr_reader :verifier
41
+ attr_reader :gated_receiver, :test_case_index, :verifier
44
42
  end
45
43
  end
46
44
  end
@@ -3,21 +3,48 @@
3
3
  require 'cucumber/platform'
4
4
  require 'cucumber/term/ansicolor'
5
5
 
6
- Cucumber::Term::ANSIColor.coloring = false if !STDOUT.tty? && !ENV.key?('AUTOTEST')
6
+ Cucumber::Term::ANSIColor.coloring = false unless $stdout.tty?
7
7
 
8
8
  module Cucumber
9
9
  module Formatter
10
- # Defines aliases for coloured output. You don't invoke any methods from this
11
- # module directly, but you can change the output colours by defining
12
- # a <tt>CUCUMBER_COLORS</tt> variable in your shell, very much like how you can
13
- # tweak the familiar POSIX command <tt>ls</tt> with
14
- # <a href="http://mipsisrisc.com/rambling/2008/06/27/lscolorsls_colors-now-with-linux-support/">$LSCOLORS/$LS_COLORS</a>
10
+ # This module allows to format cucumber related outputs using ANSI escape sequences.
11
+ #
12
+ # For example, it provides a `passed` method which returns the string with
13
+ # the ANSI escape sequence to format it green per default.
14
+ #
15
+ # To use this, include or extend it in your class.
16
+ #
17
+ # Example:
18
+ #
19
+ # require 'cucumber/formatter/ansicolor'
20
+ #
21
+ # class MyFormatter
22
+ # extend Cucumber::Term::ANSIColor
23
+ #
24
+ # def on_test_step_finished(event)
25
+ # $stdout.puts undefined(event.test_step) if event.result.undefined?
26
+ # $stdout.puts passed(event.test_step) if event.result.passed?
27
+ # end
28
+ # end
29
+ #
30
+ # This module also allows the user to customize the format of cucumber outputs
31
+ # using environment variables.
32
+ #
33
+ # For instance, if your shell has a black background and a green font (like the
34
+ # "Homebrew" settings for OS X' Terminal.app), you may want to override passed
35
+ # steps to be white instead of green.
36
+ #
37
+ # Example:
38
+ #
39
+ # export CUCUMBER_COLORS="passed=white,bold:passed_param=white,bold,underline"
15
40
  #
16
41
  # The colours that you can change are:
17
42
  #
18
43
  # * <tt>undefined</tt> - defaults to <tt>yellow</tt>
19
44
  # * <tt>pending</tt> - defaults to <tt>yellow</tt>
20
45
  # * <tt>pending_param</tt> - defaults to <tt>yellow,bold</tt>
46
+ # * <tt>flaky</tt> - defaults to <tt>yellow</tt>
47
+ # * <tt>flaky_param</tt> - defaults to <tt>yellow,bold</tt>
21
48
  # * <tt>failed</tt> - defaults to <tt>red</tt>
22
49
  # * <tt>failed_param</tt> - defaults to <tt>red,bold</tt>
23
50
  # * <tt>passed</tt> - defaults to <tt>green</tt>
@@ -29,46 +56,39 @@ module Cucumber
29
56
  # * <tt>comment</tt> - defaults to <tt>grey</tt>
30
57
  # * <tt>tag</tt> - defaults to <tt>cyan</tt>
31
58
  #
32
- # For instance, if your shell has a black background and a green font (like the
33
- # "Homebrew" settings for OS X' Terminal.app), you may want to override passed
34
- # steps to be white instead of green.
35
- #
36
- # Although not listed, you can also use <tt>grey</tt>.
37
- #
38
- # Examples: (On Windows, use SET instead of export.)
39
- #
40
- # export CUCUMBER_COLORS="passed=white"
41
- # export CUCUMBER_COLORS="passed=white,bold:passed_param=white,bold,underline"
42
- #
43
59
  # To see what colours and effects are available, just run this in your shell:
44
60
  #
45
- # ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Cucumber::Term::ANSIColor.attributes"
61
+ # ruby -e "require 'rubygems'; require 'cucumber/term/ansicolor'; puts Cucumber::Term::ANSIColor.attributes"
46
62
  #
47
63
  module ANSIColor
48
64
  include Cucumber::Term::ANSIColor
49
65
 
50
66
  ALIASES = Hash.new do |h, k|
51
- h[Regexp.last_match(1)] + ',bold' if k.to_s =~ /(.*)_param/
67
+ next unless k.to_s =~ /(.*)_param/
68
+
69
+ "#{h[Regexp.last_match(1)]},bold"
52
70
  end.merge(
53
71
  'undefined' => 'yellow',
54
- 'pending' => 'yellow',
55
- 'flaky' => 'yellow',
56
- 'failed' => 'red',
57
- 'passed' => 'green',
58
- 'outline' => 'cyan',
59
- 'skipped' => 'cyan',
60
- 'comment' => 'grey',
61
- 'tag' => 'cyan'
72
+ 'pending' => 'yellow',
73
+ 'flaky' => 'yellow',
74
+ 'failed' => 'red',
75
+ 'passed' => 'green',
76
+ 'outline' => 'cyan',
77
+ 'skipped' => 'cyan',
78
+ 'comment' => 'grey',
79
+ 'tag' => 'cyan'
62
80
  )
63
81
 
64
- if ENV['CUCUMBER_COLORS'] # Example: export CUCUMBER_COLORS="passed=red:failed=yellow"
65
- ENV['CUCUMBER_COLORS'].split(':').each do |pair|
82
+ # Apply the custom color scheme -> i.e. apply_custom_colors('passed=white')
83
+ def self.apply_custom_colors(colors)
84
+ colors.split(':').each do |pair|
66
85
  a = pair.split('=')
67
86
  ALIASES[a[0]] = a[1]
68
87
  end
69
88
  end
89
+ apply_custom_colors(ENV['CUCUMBER_COLORS']) if ENV['CUCUMBER_COLORS']
70
90
 
71
- # Eval to define the color-named methods required by Term::ANSIColor.
91
+ # Define the color-named methods required by Term::ANSIColor.
72
92
  #
73
93
  # Examples:
74
94
  #
@@ -80,67 +100,39 @@ module Cucumber
80
100
  # red(bold(string, &proc)) + red
81
101
  # end
82
102
  ALIASES.each_key do |method_name|
83
- next if method_name =~ /.*_param/
84
- code = <<-COLOR
85
- def #{method_name}(string=nil, &proc)
86
- #{ALIASES[method_name].split(',').join('(') + '(string, &proc' + ')' * ALIASES[method_name].split(',').length}
87
- end
88
- # This resets the colour to the non-param colour
89
- def #{method_name}_param(string=nil, &proc)
90
- #{ALIASES[method_name + '_param'].split(',').join('(') + '(string, &proc' + ')' * ALIASES[method_name + '_param'].split(',').length} + #{ALIASES[method_name].split(',').join(' + ')}
91
- end
92
- COLOR
93
- eval(code) # rubocop:disable Security/Eval
94
- end
103
+ next if method_name.end_with?('_param')
95
104
 
96
- def self.define_grey #:nodoc:
97
- gem 'genki-ruby-terminfo'
98
- require 'terminfo'
99
- case TermInfo.default_object.tigetnum('colors')
100
- when 0
101
- raise "Your terminal doesn't support colours."
102
- when 1
103
- ::Cucumber::Term::ANSIColor.coloring = false
104
- alias_method :grey, :white
105
- when 2..8
106
- alias_method :grey, :white # rubocop:disable Lint/DuplicateMethods
107
- else
108
- define_real_grey
105
+ define_method(method_name) do |text = nil, &proc|
106
+ apply_styles(ALIASES[method_name], text, &proc)
109
107
  end
110
- rescue Exception => e # rubocop:disable Lint/RescueException
111
- if e.class.name == 'TermInfo::TermInfoError'
112
- STDERR.puts '*** WARNING ***'
113
- STDERR.puts "You have the genki-ruby-terminfo gem installed, but you haven't set your TERM variable."
114
- STDERR.puts 'Try setting it to TERM=xterm-256color to get grey colour in output.'
115
- STDERR.puts "\n"
116
- alias_method :grey, :white
117
- else
118
- define_real_grey
119
- end
120
- end
121
108
 
122
- def self.define_real_grey #:nodoc:
123
- define_method :grey do |string|
124
- ::Cucumber::Term::ANSIColor.coloring? ? "\e[90m#{string}\e[0m" : string
109
+ define_method("#{method_name}_param") do |text = nil, &proc|
110
+ apply_styles(ALIASES["#{method_name}_param"], text, &proc) + apply_styles(ALIASES[method_name])
125
111
  end
126
112
  end
127
113
 
128
- define_grey
114
+ def cukes(amount)
115
+ ('(::) ' * amount).strip
116
+ end
129
117
 
130
- def cukes(n)
131
- ('(::) ' * n).strip
118
+ def green_cukes(amount)
119
+ blink(green(cukes(amount)))
132
120
  end
133
121
 
134
- def green_cukes(n)
135
- blink(green(cukes(n)))
122
+ def red_cukes(amount)
123
+ blink(red(cukes(amount)))
136
124
  end
137
125
 
138
- def red_cukes(n)
139
- blink(red(cukes(n)))
126
+ def yellow_cukes(amount)
127
+ blink(yellow(cukes(amount)))
140
128
  end
141
129
 
142
- def yellow_cukes(n)
143
- blink(yellow(cukes(n)))
130
+ private
131
+
132
+ def apply_styles(styles, text = nil, &proc)
133
+ styles.split(',').reverse.reduce(text) do |result, method_name|
134
+ send(method_name, result, &proc)
135
+ end
144
136
  end
145
137
  end
146
138
  end
@@ -45,11 +45,11 @@ module Cucumber
45
45
  break
46
46
  end
47
47
  break if node.previous_node.nil?
48
+
48
49
  node = node.previous_node
49
50
  end
50
51
  keyword = dialect.given_keywords.reject { |kw| kw == '* ' }[0] if keyword.nil?
51
- keyword = Cucumber::Gherkin::I18n.code_keyword_for(keyword)
52
- keyword
52
+ Cucumber::Gherkin::I18n.code_keyword_for(keyword)
53
53
  end
54
54
 
55
55
  ScenarioSource = Struct.new(:type, :scenario)
@@ -112,16 +112,24 @@ module Cucumber
112
112
  if child.respond_to?(:rule) && child.rule
113
113
  process_scenario_container(child.rule)
114
114
  elsif child.respond_to?(:scenario) && child.scenario
115
- child.scenario.steps.each do |step|
116
- @lookup_hash[step.location.line] = StepSource.new(:Step, step)
117
- end
115
+ store_scenario_source_steps(child.scenario)
118
116
  elsif !child.background.nil?
119
- child.background.steps.each do |step|
120
- @lookup_hash[step.location.line] = StepSource.new(:Step, step)
121
- end
117
+ store_background_source_steps(child.background)
122
118
  end
123
119
  end
124
120
  end
121
+
122
+ def store_scenario_source_steps(scenario)
123
+ scenario.steps.each do |step|
124
+ @lookup_hash[step.location.line] = StepSource.new(:Step, step)
125
+ end
126
+ end
127
+
128
+ def store_background_source_steps(background)
129
+ background.steps.each do |step|
130
+ @lookup_hash[step.location.line] = StepSource.new(:Step, step)
131
+ end
132
+ end
125
133
  end
126
134
 
127
135
  KeywordSearchNode = Struct.new(:keyword, :previous_node)
@@ -22,6 +22,7 @@ module Cucumber
22
22
  @backtrace_filters << RbConfig::CONFIG['rubylibdir'] if RbConfig::CONFIG['rubylibdir']
23
23
 
24
24
  @backtrace_filters << 'org/jruby/' if ::Cucumber::JRUBY
25
+ @backtrace_filters << '<internal:' if RUBY_ENGINE == 'truffleruby'
25
26
 
26
27
  BACKTRACE_FILTER_PATTERNS = Regexp.new(@backtrace_filters.join('|'))
27
28
 
@@ -33,7 +34,7 @@ module Cucumber
33
34
  def exception
34
35
  return @exception if ::Cucumber.use_full_backtrace
35
36
 
36
- pwd_pattern = /#{::Regexp.escape(::Dir.pwd)}\//m # rubocop:disable Style/RegexpLiteral
37
+ pwd_pattern = /#{::Regexp.escape(::Dir.pwd)}\//m
37
38
  backtrace = @exception.backtrace.map { |line| line.gsub(pwd_pattern, './') }
38
39
 
39
40
  filtered = (backtrace || []).reject do |line|