cucumber 3.0.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +216 -17
  3. data/CONTRIBUTING.md +4 -21
  4. data/README.md +8 -10
  5. data/bin/cucumber +1 -1
  6. data/lib/autotest/cucumber.rb +1 -0
  7. data/lib/autotest/cucumber_mixin.rb +35 -39
  8. data/lib/autotest/cucumber_rails.rb +1 -0
  9. data/lib/autotest/cucumber_rails_rspec.rb +1 -0
  10. data/lib/autotest/cucumber_rails_rspec2.rb +1 -0
  11. data/lib/autotest/cucumber_rspec.rb +1 -0
  12. data/lib/autotest/cucumber_rspec2.rb +1 -0
  13. data/lib/autotest/discover.rb +1 -0
  14. data/lib/cucumber.rb +2 -1
  15. data/lib/cucumber/cli/configuration.rb +6 -5
  16. data/lib/cucumber/cli/main.rb +14 -14
  17. data/lib/cucumber/cli/options.rb +113 -116
  18. data/lib/cucumber/cli/profile_loader.rb +50 -29
  19. data/lib/cucumber/cli/rerun_file.rb +1 -0
  20. data/lib/cucumber/configuration.rb +38 -29
  21. data/lib/cucumber/constantize.rb +8 -10
  22. data/lib/cucumber/core_ext/string.rb +1 -0
  23. data/lib/cucumber/deprecate.rb +32 -8
  24. data/lib/cucumber/encoding.rb +2 -1
  25. data/lib/cucumber/errors.rb +6 -7
  26. data/lib/cucumber/events.rb +14 -7
  27. data/lib/cucumber/events/envelope.rb +9 -0
  28. data/lib/cucumber/events/gherkin_source_parsed.rb +11 -0
  29. data/lib/cucumber/events/gherkin_source_read.rb +1 -4
  30. data/lib/cucumber/events/hook_test_step_created.rb +13 -0
  31. data/lib/cucumber/events/step_activated.rb +6 -6
  32. data/lib/cucumber/events/step_definition_registered.rb +4 -8
  33. data/lib/cucumber/events/test_case_created.rb +13 -0
  34. data/lib/cucumber/events/test_case_finished.rb +0 -4
  35. data/lib/cucumber/events/test_case_ready.rb +12 -0
  36. data/lib/cucumber/events/test_case_started.rb +0 -4
  37. data/lib/cucumber/events/test_run_finished.rb +2 -3
  38. data/lib/cucumber/events/test_run_started.rb +2 -4
  39. data/lib/cucumber/events/test_step_created.rb +13 -0
  40. data/lib/cucumber/events/test_step_finished.rb +0 -4
  41. data/lib/cucumber/events/test_step_started.rb +1 -5
  42. data/lib/cucumber/events/undefined_parameter_type.rb +10 -0
  43. data/lib/cucumber/file_specs.rb +7 -6
  44. data/lib/cucumber/filters.rb +2 -0
  45. data/lib/cucumber/filters/activate_steps.rb +6 -4
  46. data/lib/cucumber/filters/apply_after_hooks.rb +1 -0
  47. data/lib/cucumber/filters/apply_after_step_hooks.rb +1 -0
  48. data/lib/cucumber/filters/apply_around_hooks.rb +1 -0
  49. data/lib/cucumber/filters/apply_before_hooks.rb +1 -0
  50. data/lib/cucumber/filters/broadcast_test_case_ready_event.rb +12 -0
  51. data/lib/cucumber/filters/broadcast_test_run_started_event.rb +2 -1
  52. data/lib/cucumber/filters/gated_receiver.rb +1 -2
  53. data/lib/cucumber/filters/prepare_world.rb +6 -13
  54. data/lib/cucumber/filters/quit.rb +3 -6
  55. data/lib/cucumber/filters/randomizer.rb +6 -7
  56. data/lib/cucumber/filters/retry.rb +2 -2
  57. data/lib/cucumber/filters/tag_limits.rb +2 -2
  58. data/lib/cucumber/filters/tag_limits/test_case_index.rb +1 -2
  59. data/lib/cucumber/filters/tag_limits/verifier.rb +3 -6
  60. data/lib/cucumber/formatter/ansicolor.rb +33 -37
  61. data/lib/cucumber/formatter/ast_lookup.rb +165 -0
  62. data/lib/cucumber/formatter/backtrace_filter.rb +10 -10
  63. data/lib/cucumber/formatter/console.rb +65 -74
  64. data/lib/cucumber/formatter/console_counts.rb +4 -9
  65. data/lib/cucumber/formatter/console_issues.rb +9 -6
  66. data/lib/cucumber/formatter/duration.rb +2 -1
  67. data/lib/cucumber/formatter/duration_extractor.rb +4 -2
  68. data/lib/cucumber/formatter/errors.rb +6 -0
  69. data/lib/cucumber/formatter/fail_fast.rb +9 -6
  70. data/lib/cucumber/formatter/fanout.rb +3 -3
  71. data/lib/cucumber/formatter/html.rb +11 -602
  72. data/lib/cucumber/formatter/http_io.rb +146 -0
  73. data/lib/cucumber/formatter/ignore_missing_messages.rb +2 -3
  74. data/lib/cucumber/formatter/interceptor.rb +11 -18
  75. data/lib/cucumber/formatter/io.rb +18 -11
  76. data/lib/cucumber/formatter/json.rb +102 -109
  77. data/lib/cucumber/formatter/junit.rb +73 -68
  78. data/lib/cucumber/formatter/message.rb +22 -0
  79. data/lib/cucumber/formatter/message_builder.rb +255 -0
  80. data/lib/cucumber/formatter/pretty.rb +360 -153
  81. data/lib/cucumber/formatter/progress.rb +31 -32
  82. data/lib/cucumber/formatter/query/hook_by_test_step.rb +31 -0
  83. data/lib/cucumber/formatter/query/pickle_by_test.rb +26 -0
  84. data/lib/cucumber/formatter/query/pickle_step_by_test_step.rb +26 -0
  85. data/lib/cucumber/formatter/query/step_definitions_by_test_step.rb +40 -0
  86. data/lib/cucumber/formatter/query/test_case_started_by_test_case.rb +40 -0
  87. data/lib/cucumber/formatter/rerun.rb +23 -4
  88. data/lib/cucumber/formatter/stepdefs.rb +2 -2
  89. data/lib/cucumber/formatter/steps.rb +4 -5
  90. data/lib/cucumber/formatter/summary.rb +17 -9
  91. data/lib/cucumber/formatter/unicode.rb +16 -18
  92. data/lib/cucumber/formatter/usage.rb +30 -26
  93. data/lib/cucumber/gherkin/data_table_parser.rb +18 -6
  94. data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +83 -86
  95. data/lib/cucumber/gherkin/formatter/escaping.rb +13 -12
  96. data/lib/cucumber/gherkin/i18n.rb +1 -0
  97. data/lib/cucumber/gherkin/steps_parser.rb +18 -8
  98. data/lib/cucumber/glue/dsl.rb +2 -1
  99. data/lib/cucumber/glue/hook.rb +35 -11
  100. data/lib/cucumber/glue/invoke_in_world.rb +15 -20
  101. data/lib/cucumber/glue/proto_world.rb +47 -39
  102. data/lib/cucumber/glue/registry_and_more.rb +54 -23
  103. data/lib/cucumber/glue/snippet.rb +24 -27
  104. data/lib/cucumber/glue/step_definition.rb +51 -28
  105. data/lib/cucumber/glue/world_factory.rb +1 -3
  106. data/lib/cucumber/hooks.rb +24 -14
  107. data/lib/cucumber/load_path.rb +1 -0
  108. data/lib/cucumber/multiline_argument.rb +6 -8
  109. data/lib/cucumber/multiline_argument/data_table.rb +106 -73
  110. data/lib/cucumber/multiline_argument/data_table/diff_matrices.rb +8 -11
  111. data/lib/cucumber/multiline_argument/doc_string.rb +2 -1
  112. data/lib/cucumber/platform.rb +4 -3
  113. data/lib/cucumber/project_initializer.rb +1 -1
  114. data/lib/cucumber/rake/task.rb +21 -18
  115. data/lib/cucumber/rspec/disable_option_parser.rb +10 -8
  116. data/lib/cucumber/rspec/doubles.rb +1 -0
  117. data/lib/cucumber/running_test_case.rb +4 -54
  118. data/lib/cucumber/runtime.rb +57 -61
  119. data/lib/cucumber/runtime/after_hooks.rb +9 -4
  120. data/lib/cucumber/runtime/before_hooks.rb +9 -4
  121. data/lib/cucumber/runtime/for_programming_languages.rb +12 -9
  122. data/lib/cucumber/runtime/step_hooks.rb +5 -2
  123. data/lib/cucumber/runtime/support_code.rb +16 -22
  124. data/lib/cucumber/runtime/user_interface.rb +8 -19
  125. data/lib/cucumber/step_definition_light.rb +6 -4
  126. data/lib/cucumber/step_definitions.rb +3 -2
  127. data/lib/cucumber/step_match.rb +20 -18
  128. data/lib/cucumber/step_match_search.rb +9 -9
  129. data/lib/cucumber/term/ansicolor.rb +39 -39
  130. data/lib/cucumber/unit.rb +1 -0
  131. data/lib/cucumber/version +1 -1
  132. data/lib/simplecov_setup.rb +1 -0
  133. metadata +214 -127
  134. data/lib/cucumber/formatter/cucumber.css +0 -286
  135. data/lib/cucumber/formatter/cucumber.sass +0 -247
  136. data/lib/cucumber/formatter/hook_query_visitor.rb +0 -41
  137. data/lib/cucumber/formatter/html_builder.rb +0 -120
  138. data/lib/cucumber/formatter/inline-js.js +0 -30
  139. data/lib/cucumber/formatter/jquery-min.js +0 -154
  140. data/lib/cucumber/formatter/json_pretty.rb +0 -10
  141. data/lib/cucumber/formatter/legacy_api/adapter.rb +0 -1028
  142. data/lib/cucumber/formatter/legacy_api/ast.rb +0 -394
  143. data/lib/cucumber/formatter/legacy_api/results.rb +0 -50
  144. data/lib/cucumber/formatter/legacy_api/runtime_facade.rb +0 -32
  145. data/lib/cucumber/step_argument.rb +0 -24
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Require this file if you need Unicode support.
3
4
  # Tips for improvement - esp. ruby 1.9: http://www.ruby-forum.com/topic/184730
4
5
  require 'cucumber/platform'
@@ -8,40 +9,37 @@ if Cucumber::WINDOWS
8
9
  if ENV['CUCUMBER_OUTPUT_ENCODING']
9
10
  Cucumber::CODEPAGE = ENV['CUCUMBER_OUTPUT_ENCODING']
10
11
  elsif `cmd /c chcp` =~ /(\d+)/
11
- if [65000, 65001].include? $1.to_i
12
- Cucumber::CODEPAGE = 'UTF-8'
12
+ if [65_000, 65_001].include? Regexp.last_match(1).to_i
13
+ Cucumber::CODEPAGE = 'UTF-8'.freeze
13
14
  ENV['ANSICON_API'] = 'ruby'
14
15
  else
15
- Cucumber::CODEPAGE = "cp#{$1.to_i}"
16
+ Cucumber::CODEPAGE = "cp#{Regexp.last_match(1).to_i}".freeze
16
17
  end
17
18
  else
18
- Cucumber::CODEPAGE = 'cp1252'
19
+ Cucumber::CODEPAGE = 'cp1252'.freeze
19
20
  STDERR.puts("WARNING: Couldn't detect your output codepage. Assuming it is 1252. You may have to chcp 1252 or SET CUCUMBER_OUTPUT_ENCODING=cp1252.")
20
21
  end
21
22
 
22
23
  module Cucumber
23
24
  # @private
24
25
  module WindowsOutput
25
- def self.extended(o)
26
- o.instance_eval do
27
-
28
- def cucumber_preprocess_output(*a)
29
- begin
30
- a.map{|arg| arg.to_s.encode(Encoding.default_external)}
31
- rescue Encoding::UndefinedConversionError => e
32
- STDERR.cucumber_puts("WARNING: #{e.message}")
33
- a
34
- end
26
+ def self.extended(output)
27
+ output.instance_eval do
28
+ def cucumber_preprocess_output(*out)
29
+ out.map { |arg| arg.to_s.encode(Encoding.default_external) }
30
+ rescue Encoding::UndefinedConversionError => e
31
+ STDERR.cucumber_puts("WARNING: #{e.message}")
32
+ out
35
33
  end
36
34
 
37
35
  alias cucumber_print print
38
- def print(*a)
39
- cucumber_print(*cucumber_preprocess_output(*a))
36
+ def print(*out)
37
+ cucumber_print(*cucumber_preprocess_output(*out))
40
38
  end
41
39
 
42
40
  alias cucumber_puts puts
43
- def puts(*a)
44
- cucumber_puts(*cucumber_preprocess_output(*a))
41
+ def puts(*out)
42
+ cucumber_puts(*cucumber_preprocess_output(*out))
45
43
  end
46
44
  end
47
45
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'cucumber/formatter/progress'
3
4
  require 'cucumber/step_definition_light'
4
5
 
5
6
  module Cucumber
6
7
  module Formatter
7
8
  class Usage < Progress
8
-
9
9
  class StepDefKey < StepDefinitionLight
10
10
  attr_accessor :mean_duration, :status
11
11
  end
@@ -17,7 +17,7 @@ module Cucumber
17
17
  @matches = {}
18
18
  config.on_event :step_activated do |event|
19
19
  test_step, step_match = *event.attributes
20
- @matches[test_step.source] = step_match
20
+ @matches[test_step.to_s] = step_match
21
21
  end
22
22
  config.on_event :step_definition_registered, &method(:on_step_definition_registered)
23
23
  end
@@ -28,29 +28,34 @@ module Cucumber
28
28
  end
29
29
 
30
30
  def on_step_match(event)
31
- @matches[event.test_step.source] = event.step_match
31
+ @matches[event.test_step.to_s] = event.step_match
32
32
  super
33
33
  end
34
34
 
35
35
  def on_test_step_finished(event)
36
- return if HookQueryVisitor.new(event.test_step).hook?
36
+ return if event.test_step.hook?
37
37
 
38
38
  test_step = event.test_step
39
39
  result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
40
- step_match = @matches[test_step.source]
41
- step_definition = step_match.step_definition
42
- stepdef_key = StepDefKey.new(step_definition.expression.to_s, step_definition.location)
43
- unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location
44
- duration = DurationExtractor.new(result).result_duration
45
-
46
- @stepdef_to_match[stepdef_key] << {
47
- keyword: test_step.source.last.keyword,
48
- step_match: step_match,
49
- status: result.to_sym,
50
- location: test_step.location,
51
- duration: duration
52
- }
40
+ step_match = @matches[test_step.to_s]
41
+
42
+ unless step_match.nil?
43
+ step_definition = step_match.step_definition
44
+ stepdef_key = StepDefKey.new(step_definition.expression.to_s, step_definition.location)
45
+ unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location
46
+ duration = DurationExtractor.new(result).result_duration
47
+ keyword = @ast_lookup.step_source(test_step).step.keyword
48
+
49
+ @stepdef_to_match[stepdef_key] << {
50
+ keyword: keyword,
51
+ step_match: step_match,
52
+ status: result.to_sym,
53
+ location: test_step.location,
54
+ duration: duration
55
+ }
56
+ end
53
57
  end
58
+
54
59
  super
55
60
  end
56
61
 
@@ -60,9 +65,9 @@ module Cucumber
60
65
  aggregate_info
61
66
 
62
67
  keys = if config.dry_run?
63
- @stepdef_to_match.keys.sort {|a,b| a.regexp_source <=> b.regexp_source}
68
+ @stepdef_to_match.keys.sort_by(&:regexp_source)
64
69
  else
65
- @stepdef_to_match.keys.sort {|a,b| a.mean_duration <=> b.mean_duration}.reverse
70
+ @stepdef_to_match.keys.sort_by(&:mean_duration).reverse
66
71
  end
67
72
 
68
73
  keys.each do |stepdef_key|
@@ -79,7 +84,7 @@ module Cucumber
79
84
  end
80
85
 
81
86
  def print_step_definition(stepdef_key)
82
- @io.print format_string(format('%.7f', stepdef_key.mean_duration), :skipped) + ' ' unless config.dry_run?
87
+ @io.print format_string(format('%<duration>.7f', duration: stepdef_key.mean_duration), :skipped) + ' ' unless config.dry_run?
83
88
  @io.print format_string(stepdef_key.regexp_source, stepdef_key.status)
84
89
  if config.source?
85
90
  indent = max_length - stepdef_key.regexp_source.unpack('U*').length
@@ -92,7 +97,7 @@ module Cucumber
92
97
  def print_steps(stepdef_key)
93
98
  @stepdef_to_match[stepdef_key].each do |step|
94
99
  @io.print ' '
95
- @io.print format_string(format('%.7f', step[:duration]), :skipped) + ' ' unless config.dry_run?
100
+ @io.print format_string(format('%<duration>.7f', duration: step[:duration]), :skipped) + ' ' unless config.dry_run?
96
101
  @io.print format_step(step[:keyword], step[:step_match], step[:status], nil)
97
102
  if config.source?
98
103
  indent = max_length - (step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length)
@@ -108,7 +113,7 @@ module Cucumber
108
113
  end
109
114
 
110
115
  def max_stepdef_length
111
- @stepdef_to_match.keys.flatten.map{|key| key.regexp_source.unpack('U*').length}.max
116
+ @stepdef_to_match.keys.flatten.map { |key| key.regexp_source.unpack('U*').length }.max
112
117
  end
113
118
 
114
119
  def max_step_length
@@ -123,19 +128,18 @@ module Cucumber
123
128
  key.status = :skipped
124
129
  key.mean_duration = 0
125
130
  else
126
- key.status = worst_status(steps.map{ |step| step[:status] })
127
- total_duration = steps.inject(0) {|sum, step| step[:duration] + sum}
131
+ key.status = worst_status(steps.map { |step| step[:status] })
132
+ total_duration = steps.inject(0) { |sum, step| step[:duration] + sum }
128
133
  key.mean_duration = total_duration / steps.length
129
134
  end
130
135
  end
131
136
  end
132
137
 
133
138
  def worst_status(statuses)
134
- [:passed, :undefined, :pending, :skipped, :failed].find do |status|
139
+ %i[passed undefined pending skipped failed].find do |status|
135
140
  statuses.include?(status)
136
141
  end
137
142
  end
138
-
139
143
  end
140
144
  end
141
145
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'gherkin/token_scanner'
3
- require 'gherkin/parser'
2
+
3
+ require 'gherkin'
4
4
  require 'gherkin/dialect'
5
5
 
6
6
  module Cucumber
@@ -11,15 +11,27 @@ module Cucumber
11
11
  end
12
12
 
13
13
  def parse(text)
14
- token_scanner = ::Gherkin::TokenScanner.new(feature_header + text)
15
- parser = ::Gherkin::Parser.new
16
- gherkin_document = parser.parse(token_scanner)
14
+ gherkin_document = nil
15
+ messages = ::Gherkin.from_source('dummy', feature_header + text, gherkin_options)
16
+
17
+ messages.each do |message|
18
+ gherkin_document = message.gherkin_document.to_hash unless message.gherkin_document.nil?
19
+ end
17
20
 
18
- gherkin_document[:feature][:children][0][:steps][0][:argument][:rows].each do |row|
21
+ return if gherkin_document.nil?
22
+ gherkin_document[:feature][:children][0][:scenario][:steps][0][:data_table][:rows].each do |row|
19
23
  @builder.row(row[:cells].map { |cell| cell[:value] })
20
24
  end
21
25
  end
22
26
 
27
+ def gherkin_options
28
+ {
29
+ include_source: false,
30
+ include_gherkin_document: true,
31
+ include_pickles: false
32
+ }
33
+ end
34
+
23
35
  def feature_header
24
36
  dialect = ::Gherkin::Dialect.for('en')
25
37
  %(#{dialect.feature_keywords[0]}:
@@ -1,100 +1,97 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Cucumber
3
- module Gherkin
4
- module Formatter
5
- # Defines aliases for ANSI coloured output. Default colours can be overridden by defining
6
- # a <tt>GHERKIN_COLORS</tt> variable in your shell, very much like how you can
7
- # tweak the familiar POSIX command <tt>ls</tt> with
8
- # $LSCOLORS: http://linux-sxs.org/housekeeping/lscolors.html
9
- #
10
- # The colours that you can change are:
11
- #
12
- # <tt>undefined</tt>:: defaults to <tt>yellow</tt>
13
- # <tt>pending</tt>:: defaults to <tt>yellow</tt>
14
- # <tt>pending_arg</tt>:: defaults to <tt>yellow,bold</tt>
15
- # <tt>executing</tt>:: defaults to <tt>grey</tt>
16
- # <tt>executing_arg</tt>:: defaults to <tt>grey,bold</tt>
17
- # <tt>failed</tt>:: defaults to <tt>red</tt>
18
- # <tt>failed_arg</tt>:: defaults to <tt>red,bold</tt>
19
- # <tt>passed</tt>:: defaults to <tt>green</tt>
20
- # <tt>passed_arg</tt>:: defaults to <tt>green,bold</tt>
21
- # <tt>outline</tt>:: defaults to <tt>cyan</tt>
22
- # <tt>outline_arg</tt>:: defaults to <tt>cyan,bold</tt>
23
- # <tt>skipped</tt>:: defaults to <tt>cyan</tt>
24
- # <tt>skipped_arg</tt>:: defaults to <tt>cyan,bold</tt>
25
- # <tt>comment</tt>:: defaults to <tt>grey</tt>
26
- # <tt>tag</tt>:: defaults to <tt>cyan</tt>
27
- #
28
- # For instance, if your shell has a black background and a green font (like the
29
- # "Homebrew" settings for OS X' Terminal.app), you may want to override passed
30
- # steps to be white instead of green. Examples:
31
- #
32
- # export GHERKIN_COLORS="passed=white"
33
- # export GHERKIN_COLORS="passed=white,bold:passed_arg=white,bold,underline"
34
- #
35
- # (If you're on Windows, use SET instead of export).
36
- # To see what colours and effects are available, just run this in your shell:
37
- #
38
- # ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"
39
- #
40
- # Although not listed, you can also use <tt>grey</tt>
41
- module AnsiEscapes
42
- COLORS = {
43
- 'black' => "\e[30m",
44
- 'red' => "\e[31m",
45
- 'green' => "\e[32m",
46
- 'yellow' => "\e[33m",
47
- 'blue' => "\e[34m",
48
- 'magenta' => "\e[35m",
49
- 'cyan' => "\e[36m",
50
- 'white' => "\e[37m",
51
- 'grey' => "\e[90m",
52
- 'bold' => "\e[1m"
53
- }
4
+ module Gherkin
5
+ module Formatter
6
+ # Defines aliases for ANSI coloured output. Default colours can be overridden by defining
7
+ # a <tt>GHERKIN_COLORS</tt> variable in your shell, very much like how you can
8
+ # tweak the familiar POSIX command <tt>ls</tt> with
9
+ # $LSCOLORS: http://linux-sxs.org/housekeeping/lscolors.html
10
+ #
11
+ # The colours that you can change are:
12
+ #
13
+ # <tt>undefined</tt>:: defaults to <tt>yellow</tt>
14
+ # <tt>pending</tt>:: defaults to <tt>yellow</tt>
15
+ # <tt>pending_arg</tt>:: defaults to <tt>yellow,bold</tt>
16
+ # <tt>executing</tt>:: defaults to <tt>grey</tt>
17
+ # <tt>executing_arg</tt>:: defaults to <tt>grey,bold</tt>
18
+ # <tt>failed</tt>:: defaults to <tt>red</tt>
19
+ # <tt>failed_arg</tt>:: defaults to <tt>red,bold</tt>
20
+ # <tt>passed</tt>:: defaults to <tt>green</tt>
21
+ # <tt>passed_arg</tt>:: defaults to <tt>green,bold</tt>
22
+ # <tt>outline</tt>:: defaults to <tt>cyan</tt>
23
+ # <tt>outline_arg</tt>:: defaults to <tt>cyan,bold</tt>
24
+ # <tt>skipped</tt>:: defaults to <tt>cyan</tt>
25
+ # <tt>skipped_arg</tt>:: defaults to <tt>cyan,bold</tt>
26
+ # <tt>comment</tt>:: defaults to <tt>grey</tt>
27
+ # <tt>tag</tt>:: defaults to <tt>cyan</tt>
28
+ #
29
+ # For instance, if your shell has a black background and a green font (like the
30
+ # "Homebrew" settings for OS X' Terminal.app), you may want to override passed
31
+ # steps to be white instead of green. Examples:
32
+ #
33
+ # export GHERKIN_COLORS="passed=white"
34
+ # export GHERKIN_COLORS="passed=white,bold:passed_arg=white,bold,underline"
35
+ #
36
+ # (If you're on Windows, use SET instead of export).
37
+ # To see what colours and effects are available, just run this in your shell:
38
+ #
39
+ # ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"
40
+ #
41
+ # Although not listed, you can also use <tt>grey</tt>
42
+ module AnsiEscapes
43
+ COLORS = {
44
+ 'black' => "\e[30m",
45
+ 'red' => "\e[31m",
46
+ 'green' => "\e[32m",
47
+ 'yellow' => "\e[33m",
48
+ 'blue' => "\e[34m",
49
+ 'magenta' => "\e[35m",
50
+ 'cyan' => "\e[36m",
51
+ 'white' => "\e[37m",
52
+ 'grey' => "\e[90m",
53
+ 'bold' => "\e[1m"
54
+ }.freeze
54
55
 
55
- ALIASES = Hash.new do |h,k|
56
- if k.to_s =~ /(.*)_arg/
57
- h[$1] + ',bold'
58
- end
59
- end.merge({
60
- 'undefined' => 'yellow',
61
- 'pending' => 'yellow',
62
- 'executing' => 'grey',
63
- 'failed' => 'red',
64
- 'passed' => 'green',
65
- 'outline' => 'cyan',
66
- 'skipped' => 'cyan',
67
- 'comments' => 'grey',
68
- 'tag' => 'cyan'
69
- })
56
+ ALIASES = Hash.new do |h, k|
57
+ h[Regexp.last_match(1)] + ',bold' if k.to_s =~ /(.*)_arg/
58
+ end.merge(
59
+ 'undefined' => 'yellow',
60
+ 'pending' => 'yellow',
61
+ 'executing' => 'grey',
62
+ 'failed' => 'red',
63
+ 'passed' => 'green',
64
+ 'outline' => 'cyan',
65
+ 'skipped' => 'cyan',
66
+ 'comments' => 'grey',
67
+ 'tag' => 'cyan'
68
+ )
70
69
 
71
- if ENV['GHERKIN_COLORS'] # Example: export GHERKIN_COLORS="passed=red:failed=yellow"
72
- ENV['GHERKIN_COLORS'].split(':').each do |pair|
73
- a = pair.split('=')
74
- ALIASES[a[0]] = a[1]
70
+ if ENV['GHERKIN_COLORS'] # Example: export GHERKIN_COLORS="passed=red:failed=yellow"
71
+ ENV['GHERKIN_COLORS'].split(':').each do |pair|
72
+ a = pair.split('=')
73
+ ALIASES[a[0]] = a[1]
74
+ end
75
75
  end
76
- end
77
76
 
78
- ALIASES.keys.each do |key|
79
- define_method(key) do
80
- ALIASES[key].split(',').map{|color| COLORS[color]}.join('')
81
- end
77
+ ALIASES.keys.each do |key|
78
+ define_method(key) do
79
+ ALIASES[key].split(',').map { |color| COLORS[color] }.join('')
80
+ end
82
81
 
83
- define_method("#{key}_arg") do
84
- ALIASES["#{key}_arg"].split(',').map{|color| COLORS[color]}.join('')
82
+ define_method("#{key}_arg") do
83
+ ALIASES["#{key}_arg"].split(',').map { |color| COLORS[color] }.join('')
84
+ end
85
85
  end
86
- end
87
86
 
88
- def reset
89
- "\e[0m"
90
- end
87
+ def reset
88
+ "\e[0m"
89
+ end
91
90
 
92
- def up(n)
93
- "\e[#{n}A"
91
+ def up(n)
92
+ "\e[#{n}A"
93
+ end
94
94
  end
95
-
96
- extend self
97
95
  end
98
96
  end
99
97
  end
100
- end
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Cucumber
3
- module Gherkin
4
- module Formatter
5
- module Escaping
6
- # Escapes a pipes and backslashes:
7
- #
8
- # * | becomes \|
9
- # * \ becomes \\
10
- #
11
- # This is used in the pretty formatter.
12
- def escape_cell(s)
13
- s.gsub(/\\(?!\|)/, '\\\\\\\\').gsub(/\n/, '\\n').gsub(/\|/, '\\|')
4
+ module Gherkin
5
+ module Formatter
6
+ module Escaping
7
+ # Escapes a pipes and backslashes:
8
+ #
9
+ # * | becomes \|
10
+ # * \ becomes \\
11
+ #
12
+ # This is used in the pretty formatter.
13
+ def escape_cell(sym)
14
+ sym.gsub(/\\(?!\|)/, '\\\\\\\\').gsub(/\n/, '\\n').gsub(/\|/, '\\|')
15
+ end
14
16
  end
15
17
  end
16
18
  end
17
19
  end
18
- end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Cucumber
3
4
  module Gherkin
4
5
  module I18n