cucumber 2.99.0 → 3.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +22 -10
  3. data/CONTRIBUTING.md +13 -0
  4. data/Gemfile +11 -4
  5. data/History.md +19 -1
  6. data/README.md +1 -1
  7. data/cucumber.gemspec +2 -2
  8. data/cucumber.yml +2 -2
  9. data/features/docs/api/listen_for_events.feature +7 -6
  10. data/features/docs/cli/help.feature +8 -0
  11. data/features/docs/cli/retry_failing_tests.feature +51 -16
  12. data/features/docs/defining_steps/nested_steps_i18n.feature +2 -0
  13. data/features/docs/defining_steps/printing_messages.feature +0 -1
  14. data/features/docs/defining_steps/skip_scenario.feature +0 -34
  15. data/features/docs/extending_cucumber/custom_formatter.feature +2 -30
  16. data/features/docs/formatters/summary_formatter.feature +34 -0
  17. data/features/docs/gherkin/unicode_table.feature +1 -1
  18. data/features/docs/post_configuration_hook.feature +0 -16
  19. data/features/docs/writing_support_code/world.feature +129 -0
  20. data/features/lib/step_definitions/aruba_steps.rb +1 -0
  21. data/features/lib/step_definitions/cli_steps.rb +4 -0
  22. data/features/lib/step_definitions/cucumber_steps.rb +1 -0
  23. data/features/lib/step_definitions/iso-8859-1_steps.rb +1 -0
  24. data/features/lib/step_definitions/json_steps.rb +1 -0
  25. data/features/lib/step_definitions/junit_steps.rb +1 -0
  26. data/features/lib/step_definitions/language_steps.rb +1 -0
  27. data/features/lib/step_definitions/profile_steps.rb +1 -0
  28. data/features/lib/step_definitions/retry_steps.rb +32 -12
  29. data/features/lib/step_definitions/ruby_steps.rb +1 -0
  30. data/features/lib/step_definitions/wire_steps.rb +1 -0
  31. data/features/lib/support/env.rb +2 -1
  32. data/features/lib/support/fake_wire_server.rb +1 -0
  33. data/features/lib/support/feature_factory.rb +1 -0
  34. data/features/lib/support/normalise_output.rb +1 -0
  35. data/gem_tasks/contributors.rake +1 -0
  36. data/gem_tasks/cov.rake +1 -0
  37. data/gem_tasks/cucumber.rake +1 -0
  38. data/gem_tasks/downloads.rb +1 -0
  39. data/gem_tasks/environment.rake +1 -0
  40. data/gem_tasks/examples.rake +2 -1
  41. data/gem_tasks/fix_cr_lf.rake +2 -1
  42. data/gem_tasks/flog.rake +2 -1
  43. data/gem_tasks/rspec.rake +1 -0
  44. data/gem_tasks/sass.rake +2 -1
  45. data/lib/autotest/cucumber.rb +1 -0
  46. data/lib/autotest/cucumber_mixin.rb +1 -0
  47. data/lib/autotest/cucumber_rails.rb +1 -0
  48. data/lib/autotest/cucumber_rails_rspec.rb +1 -0
  49. data/lib/autotest/cucumber_rails_rspec2.rb +1 -0
  50. data/lib/autotest/cucumber_rspec.rb +1 -0
  51. data/lib/autotest/cucumber_rspec2.rb +1 -0
  52. data/lib/autotest/discover.rb +1 -0
  53. data/lib/cucumber.rb +1 -13
  54. data/lib/cucumber/cli/configuration.rb +3 -6
  55. data/lib/cucumber/cli/main.rb +2 -1
  56. data/lib/cucumber/cli/options.rb +239 -173
  57. data/lib/cucumber/cli/profile_loader.rb +1 -0
  58. data/lib/cucumber/cli/rerun_file.rb +1 -0
  59. data/lib/cucumber/configuration.rb +40 -19
  60. data/lib/cucumber/constantize.rb +1 -0
  61. data/lib/cucumber/core_ext/instance_exec.rb +1 -0
  62. data/lib/cucumber/core_ext/string.rb +1 -0
  63. data/lib/cucumber/deprecate.rb +1 -0
  64. data/lib/cucumber/encoding.rb +1 -0
  65. data/lib/cucumber/errors.rb +3 -1
  66. data/lib/cucumber/events.rb +13 -3
  67. data/lib/cucumber/events/step_definition_registered.rb +24 -0
  68. data/lib/cucumber/events/step_match.rb +4 -1
  69. data/lib/cucumber/events/test_run_finished.rb +12 -0
  70. data/lib/cucumber/file_specs.rb +1 -0
  71. data/lib/cucumber/filters.rb +2 -0
  72. data/lib/cucumber/filters/activate_steps.rb +2 -1
  73. data/lib/cucumber/filters/apply_after_hooks.rb +1 -0
  74. data/lib/cucumber/filters/apply_after_step_hooks.rb +1 -0
  75. data/lib/cucumber/filters/apply_around_hooks.rb +1 -0
  76. data/lib/cucumber/filters/apply_before_hooks.rb +1 -0
  77. data/lib/cucumber/filters/gated_receiver.rb +1 -0
  78. data/lib/cucumber/filters/prepare_world.rb +1 -0
  79. data/lib/cucumber/filters/quit.rb +1 -0
  80. data/lib/cucumber/filters/randomizer.rb +1 -0
  81. data/lib/cucumber/filters/retry.rb +3 -3
  82. data/lib/cucumber/filters/tag_limits.rb +1 -0
  83. data/lib/cucumber/filters/tag_limits/test_case_index.rb +1 -0
  84. data/lib/cucumber/filters/tag_limits/verifier.rb +1 -0
  85. data/lib/cucumber/formatter/ansicolor.rb +1 -0
  86. data/lib/cucumber/formatter/backtrace_filter.rb +3 -2
  87. data/lib/cucumber/formatter/console.rb +61 -52
  88. data/lib/cucumber/formatter/console_counts.rb +57 -0
  89. data/lib/cucumber/formatter/console_issues.rb +37 -0
  90. data/lib/cucumber/formatter/debug.rb +1 -0
  91. data/lib/cucumber/formatter/duration.rb +1 -0
  92. data/lib/cucumber/formatter/duration_extractor.rb +1 -0
  93. data/lib/cucumber/formatter/fail_fast.rb +4 -2
  94. data/lib/cucumber/formatter/fanout.rb +1 -0
  95. data/lib/cucumber/formatter/hook_query_visitor.rb +1 -0
  96. data/lib/cucumber/formatter/html.rb +6 -5
  97. data/lib/cucumber/formatter/ignore_missing_messages.rb +1 -0
  98. data/lib/cucumber/formatter/interceptor.rb +1 -0
  99. data/lib/cucumber/formatter/io.rb +1 -0
  100. data/lib/cucumber/formatter/json.rb +15 -13
  101. data/lib/cucumber/formatter/json_pretty.rb +1 -0
  102. data/lib/cucumber/formatter/junit.rb +13 -11
  103. data/lib/cucumber/formatter/legacy_api/adapter.rb +28 -32
  104. data/lib/cucumber/formatter/legacy_api/ast.rb +1 -0
  105. data/lib/cucumber/formatter/legacy_api/results.rb +1 -0
  106. data/lib/cucumber/formatter/legacy_api/runtime_facade.rb +1 -0
  107. data/lib/cucumber/formatter/pretty.rb +7 -1
  108. data/lib/cucumber/formatter/progress.rb +56 -13
  109. data/lib/cucumber/formatter/rerun.rb +15 -18
  110. data/lib/cucumber/formatter/stepdefs.rb +1 -0
  111. data/lib/cucumber/formatter/steps.rb +1 -0
  112. data/lib/cucumber/formatter/summary.rb +43 -20
  113. data/lib/cucumber/formatter/unicode.rb +1 -0
  114. data/lib/cucumber/formatter/usage.rb +26 -21
  115. data/lib/cucumber/gherkin/data_table_parser.rb +1 -0
  116. data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +1 -0
  117. data/lib/cucumber/gherkin/formatter/escaping.rb +1 -0
  118. data/lib/cucumber/gherkin/i18n.rb +1 -0
  119. data/lib/cucumber/gherkin/steps_parser.rb +1 -0
  120. data/lib/cucumber/hooks.rb +1 -0
  121. data/lib/cucumber/load_path.rb +1 -0
  122. data/lib/cucumber/multiline_argument.rb +1 -2
  123. data/lib/cucumber/multiline_argument/data_table.rb +3 -1
  124. data/lib/cucumber/multiline_argument/doc_string.rb +1 -0
  125. data/lib/cucumber/platform.rb +1 -0
  126. data/lib/cucumber/project_initializer.rb +2 -1
  127. data/lib/cucumber/rake/task.rb +1 -0
  128. data/lib/cucumber/rb_support/rb_dsl.rb +11 -9
  129. data/lib/cucumber/rb_support/rb_hook.rb +1 -0
  130. data/lib/cucumber/rb_support/rb_language.rb +19 -8
  131. data/lib/cucumber/rb_support/rb_step_definition.rb +1 -0
  132. data/lib/cucumber/rb_support/rb_transform.rb +1 -0
  133. data/lib/cucumber/rb_support/rb_world.rb +42 -20
  134. data/lib/cucumber/rb_support/snippet.rb +2 -1
  135. data/lib/cucumber/rspec/disable_option_parser.rb +1 -0
  136. data/lib/cucumber/rspec/doubles.rb +1 -0
  137. data/lib/cucumber/running_test_case.rb +1 -25
  138. data/lib/cucumber/runtime.rb +15 -10
  139. data/lib/cucumber/runtime/after_hooks.rb +1 -0
  140. data/lib/cucumber/runtime/before_hooks.rb +1 -0
  141. data/lib/cucumber/runtime/for_programming_languages.rb +1 -0
  142. data/lib/cucumber/runtime/step_hooks.rb +1 -0
  143. data/lib/cucumber/runtime/support_code.rb +1 -0
  144. data/lib/cucumber/runtime/user_interface.rb +1 -0
  145. data/lib/cucumber/step_argument.rb +1 -0
  146. data/lib/cucumber/step_definition_light.rb +1 -0
  147. data/lib/cucumber/step_definitions.rb +1 -0
  148. data/lib/cucumber/step_match.rb +1 -0
  149. data/lib/cucumber/step_match_search.rb +1 -0
  150. data/lib/cucumber/term/ansicolor.rb +1 -0
  151. data/lib/cucumber/unit.rb +1 -0
  152. data/lib/cucumber/version +1 -1
  153. data/lib/simplecov_setup.rb +1 -0
  154. data/spec/cucumber/cli/configuration_spec.rb +1 -0
  155. data/spec/cucumber/cli/main_spec.rb +1 -0
  156. data/spec/cucumber/cli/options_spec.rb +1 -0
  157. data/spec/cucumber/cli/profile_loader_spec.rb +1 -0
  158. data/spec/cucumber/cli/rerun_spec.rb +1 -0
  159. data/spec/cucumber/configuration_spec.rb +1 -0
  160. data/spec/cucumber/constantize_spec.rb +1 -0
  161. data/spec/cucumber/core_ext/instance_exec_spec.rb +1 -0
  162. data/spec/cucumber/file_specs_spec.rb +1 -0
  163. data/spec/cucumber/filters/activate_steps_spec.rb +9 -6
  164. data/spec/cucumber/filters/gated_receiver_spec.rb +1 -0
  165. data/spec/cucumber/filters/retry_spec.rb +27 -21
  166. data/spec/cucumber/filters/tag_limits/test_case_index_spec.rb +1 -0
  167. data/spec/cucumber/filters/tag_limits/verifier_spec.rb +1 -0
  168. data/spec/cucumber/filters/tag_limits_spec.rb +1 -0
  169. data/spec/cucumber/formatter/ansicolor_spec.rb +1 -0
  170. data/spec/cucumber/formatter/console_counts_spec.rb +14 -0
  171. data/spec/cucumber/formatter/debug_spec.rb +1 -0
  172. data/spec/cucumber/formatter/duration_spec.rb +1 -0
  173. data/spec/cucumber/formatter/fail_fast_spec.rb +5 -5
  174. data/spec/cucumber/formatter/html_spec.rb +6 -1
  175. data/spec/cucumber/formatter/interceptor_spec.rb +1 -0
  176. data/spec/cucumber/formatter/json_spec.rb +29 -28
  177. data/spec/cucumber/formatter/junit_spec.rb +1 -0
  178. data/spec/cucumber/formatter/legacy_api/adapter_spec.rb +8 -3
  179. data/spec/cucumber/formatter/pretty_spec.rb +1 -0
  180. data/spec/cucumber/formatter/progress_spec.rb +2 -1
  181. data/spec/cucumber/formatter/rerun_spec.rb +70 -64
  182. data/spec/cucumber/formatter/spec_helper.rb +8 -7
  183. data/spec/cucumber/hooks_spec.rb +1 -0
  184. data/spec/cucumber/multiline_argument/data_table_spec.rb +1 -0
  185. data/spec/cucumber/project_initializer_spec.rb +2 -1
  186. data/spec/cucumber/rake/forked_spec.rb +1 -0
  187. data/spec/cucumber/rake/task_spec.rb +1 -0
  188. data/spec/cucumber/rb_support/rb_language_spec.rb +81 -3
  189. data/spec/cucumber/rb_support/rb_step_definition_spec.rb +1 -0
  190. data/spec/cucumber/rb_support/rb_transform_spec.rb +1 -0
  191. data/spec/cucumber/rb_support/rb_world_spec.rb +2 -1
  192. data/spec/cucumber/rb_support/snippet_spec.rb +1 -0
  193. data/spec/cucumber/running_test_case_spec.rb +1 -0
  194. data/spec/cucumber/runtime/for_programming_languages_spec.rb +1 -0
  195. data/spec/cucumber/runtime/support_code_spec.rb +1 -0
  196. data/spec/cucumber/runtime_spec.rb +1 -0
  197. data/spec/cucumber/step_argument_spec.rb +1 -0
  198. data/spec/cucumber/step_match_search_spec.rb +1 -0
  199. data/spec/cucumber/step_match_spec.rb +1 -0
  200. data/spec/cucumber/world/pending_spec.rb +1 -0
  201. data/spec/spec_helper.rb +1 -0
  202. data/spec/support/standard_step_actions.rb +1 -0
  203. metadata +24 -23
  204. data/lib/cucumber/ast.rb +0 -13
  205. data/lib/cucumber/events/after_test_case.rb +0 -25
  206. data/lib/cucumber/events/after_test_step.rb +0 -30
  207. data/lib/cucumber/events/before_test_case.rb +0 -18
  208. data/lib/cucumber/events/before_test_step.rb +0 -23
  209. data/lib/cucumber/events/bus.rb +0 -86
  210. data/lib/cucumber/events/finished_testing.rb +0 -9
  211. data/lib/cucumber/formatter/event_bus_report.rb +0 -38
  212. data/spec/cucumber/events/bus_spec.rb +0 -94
  213. data/spec/cucumber/formatter/event_bus_report_spec.rb +0 -88
  214. data/spec/cucumber_spec.rb +0 -39
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require 'logger'
2
3
  require 'cucumber/cli/options'
3
4
  require 'cucumber/cli/rerun_file'
4
5
  require 'cucumber/constantize'
5
6
  require 'cucumber/core/gherkin/tag_expression'
7
+ require 'cucumber'
6
8
 
7
9
  module Cucumber
8
10
  module Cli
@@ -108,17 +110,12 @@ module Cucumber
108
110
  @options[:formats]
109
111
  end
110
112
 
111
- def options
112
- warn("Deprecated: Configuration#options will be removed from the next release of Cucumber. Please use the configuration object directly instead.")
113
- @options
114
- end
115
-
116
113
  def paths
117
114
  @options[:paths]
118
115
  end
119
116
 
120
117
  def to_hash
121
- Cucumber::Hash(@options).merge(out_stream: @out_stream, error_stream: @error_stream)
118
+ Hash(@options).merge(out_stream: @out_stream, error_stream: @error_stream)
122
119
  end
123
120
 
124
121
  private
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'optparse'
2
3
  require 'cucumber'
3
4
  require 'logger'
@@ -96,4 +97,4 @@ module Cucumber
96
97
  end
97
98
  end
98
99
  end
99
- end
100
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'cucumber/cli/profile_loader'
2
3
  require 'cucumber/formatter/ansicolor'
3
4
  require 'cucumber/rb_support/rb_language'
@@ -23,12 +24,11 @@ module Cucumber
23
24
  'junit' => ['Cucumber::Formatter::Junit', 'Generates a report similar to Ant+JUnit.'],
24
25
  'json' => ['Cucumber::Formatter::Json', 'Prints the feature as JSON'],
25
26
  'json_pretty' => ['Cucumber::Formatter::JsonPretty', 'Prints the feature as prettified JSON'],
26
- 'debug' => ['Cucumber::Formatter::Debug', 'For developing formatters - prints the calls made to the listeners.']
27
+ 'debug' => ['Cucumber::Formatter::Debug', 'For developing formatters - prints the calls made to the listeners.'],
28
+ 'summary' => ['Cucumber::Formatter::Summary', 'Summary output of feature and scenarios']
27
29
  }
28
30
  max = BUILTIN_FORMATS.keys.map{|s| s.length}.max
29
- FORMAT_HELP = (BUILTIN_FORMATS.keys.sort.map do |key|
30
- " #{key}#{' ' * (max - key.length)} : #{BUILTIN_FORMATS[key][1]}"
31
- end) + ["Use --format rerun --out rerun.txt to write out failing",
31
+ FORMAT_HELP_MSG = ["Use --format rerun --out rerun.txt to write out failing",
32
32
  "features. You can rerun them with cucumber @rerun.txt.",
33
33
  "FORMAT can also be the fully qualified class name of",
34
34
  "your own custom formatter. If the class isn't loaded,",
@@ -39,6 +39,10 @@ module Cucumber
39
39
  "path underneath your features/support directory or anywhere",
40
40
  "on Ruby's LOAD_PATH, for example in a Ruby gem."
41
41
  ]
42
+
43
+ FORMAT_HELP = (BUILTIN_FORMATS.keys.sort.map do |key|
44
+ " #{key}#{' ' * (max - key.length)} : #{BUILTIN_FORMATS[key][1]}"
45
+ end) + FORMAT_HELP_MSG
42
46
  PROFILE_SHORT_FLAG = '-p'
43
47
  NO_PROFILE_SHORT_FLAG = '-P'
44
48
  PROFILE_LONG_FLAG = '--profile'
@@ -85,169 +89,40 @@ module Cucumber
85
89
  @args.extend(::OptionParser::Arguable)
86
90
 
87
91
  @args.options do |opts|
88
- opts.banner = ["Usage: cucumber [options] [ [FILE|DIR|URL][:LINE[:LINE]*] ]+", "",
89
- "Examples:",
90
- "cucumber examples/i18n/en/features",
91
- "cucumber @rerun.txt (See --format rerun)",
92
- "cucumber examples/i18n/it/features/somma.feature:6:98:113",
93
- "cucumber -s -i http://rubyurl.com/eeCl", "", "",
94
- ].join("\n")
95
- opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR",
96
- "Require files before executing the features. If this",
97
- "option is not specified, all *.rb files that are",
98
- "siblings or below the features will be loaded auto-",
99
- "matically. Automatic loading is disabled when this",
100
- "option is specified, and all loading becomes explicit.",
101
- "Files under directories named \"support\" are always",
102
- "loaded first.",
103
- "This option can be specified multiple times.") do |v|
104
- @options[:require] << v
105
- if(Cucumber::JRUBY && File.directory?(v))
106
- require 'java'
107
- $CLASSPATH << v
108
- end
109
- end
92
+ opts.banner = banner
93
+ opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR", *require_files_msg) {|lib| require_files(lib) }
110
94
 
111
95
  if(Cucumber::JRUBY)
112
- opts.on("-j DIR", "--jars DIR",
113
- "Load all the jars under DIR") do |jars|
114
- Dir["#{jars}/**/*.jar"].each {|jar| require jar}
115
- end
116
- end
117
-
118
- opts.on("--i18n LANG",
119
- "List keywords for in a particular language",
120
- %{Run with "--i18n help" to see all languages}) do |lang|
121
- require 'gherkin/dialect'
122
-
123
- if lang == 'help'
124
- list_languages_and_exit
125
- elsif !::Gherkin::DIALECTS.keys.include? lang
126
- indicate_invalid_language_and_exit(lang)
127
- else
128
- list_keywords_and_exit(lang)
129
- end
130
- end
131
- opts.on(FAIL_FAST_FLAG, "Exit immediately following the first failing scenario") do |v|
132
- options[:fail_fast] = true
133
- end
134
- opts.on("-f FORMAT", "--format FORMAT",
135
- "How to format features (Default: pretty). Available formats:",
136
- *FORMAT_HELP) do |v|
137
- @options[:formats] << [v, @out_stream]
138
- end
139
- opts.on('--init',
140
- 'Initializes folder structure and generates conventional files for',
141
- 'a Cucumber project.') do |v|
142
- ProjectInitializer.new.run
143
- Kernel.exit(0)
144
- end
145
- opts.on("-o", "--out [FILE|DIR]",
146
- "Write output to a file/directory instead of STDOUT. This option",
147
- "applies to the previously specified --format, or the",
148
- "default format if no format is specified. Check the specific",
149
- "formatter's docs to see whether to pass a file or a dir.") do |v|
150
- @options[:formats] << ['pretty', nil] if @options[:formats].empty?
151
- @options[:formats][-1][1] = v
152
- end
153
- opts.on("-t TAG_EXPRESSION", "--tags TAG_EXPRESSION",
154
- "Only execute the features or scenarios with tags matching TAG_EXPRESSION.",
155
- "Scenarios inherit tags declared on the Feature level. The simplest",
156
- "TAG_EXPRESSION is simply a tag. Example: --tags @dev. When a tag in a tag",
157
- "expression starts with a ~, this represents boolean NOT. Example: --tags ~@dev.",
158
- "A tag expression can have several tags separated by a comma, which represents",
159
- "logical OR. Example: --tags @dev,@wip. The --tags option can be specified",
160
- "several times, and this represents logical AND. Example: --tags @foo,~@bar --tags @zap.",
161
- "This represents the boolean expression (@foo || !@bar) && @zap.",
162
- "\n",
163
- "Beware that if you want to use several negative tags to exclude several tags",
164
- "you have to use logical AND: --tags ~@fixme --tags ~@buggy.",
165
- "\n",
166
- "Positive tags can be given a threshold to limit the number of occurrences.",
167
- "Example: --tags @qa:3 will fail if there are more than 3 occurrences of the @qa tag.",
168
- "This can be practical if you are practicing Kanban or CONWIP.") do |v|
169
- @options[:tag_expressions] << v
170
- end
171
- opts.on("-n NAME", "--name NAME",
172
- "Only execute the feature elements which match part of the given name.",
173
- "If this option is given more than once, it will match against all the",
174
- "given names.") do |v|
175
- @options[:name_regexps] << /#{v}/
176
- end
177
- opts.on("-e", "--exclude PATTERN", "Don't run feature files or require ruby files matching PATTERN") do |v|
178
- @options[:excludes] << Regexp.new(v)
179
- end
180
- opts.on(PROFILE_SHORT_FLAG, "#{PROFILE_LONG_FLAG} PROFILE",
181
- "Pull commandline arguments from cucumber.yml which can be defined as",
182
- "strings or arrays. When a 'default' profile is defined and no profile",
183
- "is specified it is always used. (Unless disabled, see -P below.)",
184
- "When feature files are defined in a profile and on the command line",
185
- "then only the ones from the command line are used.") do |v|
186
- @profiles << v
187
- end
188
- opts.on(NO_PROFILE_SHORT_FLAG, NO_PROFILE_LONG_FLAG,
189
- "Disables all profile loading to avoid using the 'default' profile.") do |v|
190
- @disable_profile_loading = true
191
- end
192
- opts.on("#{RETRY_FLAG} ATTEMPTS", "Specify the number of times to retry failing tests (default: 0)") do |v|
193
- @options[:retry] = v.to_i
194
- end
195
- opts.on("-c", "--[no-]color",
196
- "Whether or not to use ANSI color in the output. Cucumber decides",
197
- "based on your platform and the output destination if not specified.") do |v|
198
- Cucumber::Term::ANSIColor.coloring = v
199
- end
200
- opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.",
201
- "This also omits the loading of your support/env.rb file if it exists.") do
202
- @options[:dry_run] = true
203
- @options[:duration] = false
204
- end
205
- opts.on("-m", "--no-multiline",
206
- "Don't print multiline strings and tables under steps.") do
207
- @options[:no_multiline] = true
208
- end
209
- opts.on("-s", "--no-source",
210
- "Don't print the file and line of the step definition with the steps.") do
211
- @options[:source] = false
212
- end
213
- opts.on("-i", "--no-snippets", "Don't print snippets for pending steps.") do
214
- @options[:snippets] = false
215
- end
216
- opts.on("-I", "--snippet-type TYPE",
217
- "Use different snippet type (Default: regexp). Available types:",
218
- *Cucumber::RbSupport::RbLanguage.cli_snippet_type_options) do |v|
219
- @options[:snippet_type] = v.to_sym
220
- end
96
+ opts.on("-j DIR", "--jars DIR", "Load all the jars under DIR") {|jars| load_jars(jars) }
97
+ end
98
+
99
+ opts.on("#{RETRY_FLAG} ATTEMPTS", *retry_msg) {|v| set_option :retry, v.to_i }
100
+ opts.on("--i18n LANG", *i18n_msg) {|lang| set_language lang }
101
+ opts.on(FAIL_FAST_FLAG, "Exit immediately following the first failing scenario") { set_option :fail_fast }
102
+ opts.on("-f FORMAT", "--format FORMAT", *format_msg, *FORMAT_HELP) {|v| add_option :formats, [v, @out_stream] }
103
+ opts.on('--init', *init_msg) {|v| initialize_project }
104
+ opts.on("-o", "--out [FILE|DIR]", *out_msg) {|v| set_out_stream v }
105
+ opts.on("-t TAG_EXPRESSION", "--tags TAG_EXPRESSION", *tags_msg) {|v| add_option :tag_expressions, v }
106
+ opts.on("-n NAME", "--name NAME", *name_msg) {|v| add_option :name_regexps, /#{v}/ }
107
+ opts.on("-e", "--exclude PATTERN", *exclude_msg) {|v| add_option :excludes, Regexp.new(v) }
108
+ opts.on(PROFILE_SHORT_FLAG, "#{PROFILE_LONG_FLAG} PROFILE", *profile_short_flag_msg) {|v| add_profile v }
109
+ opts.on(NO_PROFILE_SHORT_FLAG, NO_PROFILE_LONG_FLAG, *no_profile_short_flag_msg) {|v| disable_profile_loading }
110
+ opts.on("-c", "--[no-]color", *color_msg) {|v| set_color v }
111
+ opts.on("-d", "--dry-run", *dry_run_msg) { set_dry_run_and_duration }
112
+ opts.on("-m", "--no-multiline", "Don't print multiline strings and tables under steps.") { set_option :no_multiline }
113
+ opts.on("-s", "--no-source", "Don't print the file and line of the step definition with the steps.") { set_option :source, false }
114
+ opts.on("-i", "--no-snippets", "Don't print snippets for pending steps.") { set_option :snippets, false }
115
+ opts.on("-I", "--snippet-type TYPE", *snippet_type_msg) {|v| set_option :snippet_type, v.to_sym }
116
+ opts.on("-q", "--quiet", "Alias for --no-snippets --no-source.") { shut_up }
117
+ opts.on("--no-duration", "Don't print the duration at the end of the summary") { set_option :duration, false }
118
+ opts.on("-b", "--backtrace", "Show full backtrace for all errors.") { Cucumber.use_full_backtrace = true }
119
+ opts.on("-S", "--strict", "Fail if there are any undefined or pending steps.") { set_option :strict }
120
+ opts.on("-w", "--wip", "Fail if there are any passing scenarios.") { set_option :wip }
121
+ opts.on("-v", "--verbose", "Show the files and features loaded.") { set_option :verbose }
122
+ opts.on("-g", "--guess", "Guess best match for Ambiguous steps.") { set_option :guess }
123
+ opts.on("-l", "--lines LINES", *lines_msg) {|lines| set_option :lines, lines }
124
+ opts.on("-x", "--expand", "Expand Scenario Outline Tables in output.") { set_option :expand }
221
125
 
222
- opts.on("-q", "--quiet", "Alias for --no-snippets --no-source.") do
223
- @options[:snippets] = false
224
- @options[:source] = false
225
- @options[:duration] = false
226
- end
227
- opts.on("--no-duration", "Don't print the duration at the end of the summary") do
228
- @options[:duration] = false
229
- end
230
- opts.on("-b", "--backtrace", "Show full backtrace for all errors.") do
231
- Cucumber.use_full_backtrace = true
232
- end
233
- opts.on("-S", "--strict", "Fail if there are any undefined or pending steps.") do
234
- @options[:strict] = true
235
- end
236
- opts.on("-w", "--wip", "Fail if there are any passing scenarios.") do
237
- @options[:wip] = true
238
- end
239
- opts.on("-v", "--verbose", "Show the files and features loaded.") do
240
- @options[:verbose] = true
241
- end
242
- opts.on("-g", "--guess", "Guess best match for Ambiguous steps.") do
243
- @options[:guess] = true
244
- end
245
- opts.on("-l", "--lines LINES", "Run given line numbers. Equivalent to FILE:LINE syntax") do |lines|
246
- @options[:lines] = lines
247
- end
248
- opts.on("-x", "--expand", "Expand Scenario Outline Tables in output.") do
249
- @options[:expand] = true
250
- end
251
126
  opts.on("--order TYPE[:SEED]", "Run examples in the specified order. Available types:",
252
127
  *<<-TEXT.split("\n")) do |order|
253
128
  [defined] Run scenarios in the order they were defined (default).
@@ -260,14 +135,9 @@ TEXT
260
135
  fail "'#{@options[:order]}' is not a recognised order type. Please use one of #{ORDER_TYPES.join(", ")}."
261
136
  end
262
137
  end
263
- opts.on_tail("--version", "Show version.") do
264
- @out_stream.puts Cucumber::VERSION
265
- Kernel.exit(0)
266
- end
267
- opts.on_tail("-h", "--help", "You're looking at it.") do
268
- @out_stream.puts opts.help
269
- Kernel.exit(0)
270
- end
138
+
139
+ opts.on_tail("--version", "Show version.") { exit_ok(Cucumber::VERSION) }
140
+ opts.on_tail("-h", "--help", "You're looking at it.") { exit_ok(opts.help) }
271
141
  end.parse!
272
142
 
273
143
  @args.map! { |a| "#{a}:#{@options[:lines]}" } if @options[:lines]
@@ -298,7 +168,7 @@ TEXT
298
168
  end
299
169
 
300
170
  def to_hash
301
- Cucumber::Hash(@options)
171
+ Hash(@options)
302
172
  end
303
173
 
304
174
  protected
@@ -308,10 +178,206 @@ TEXT
308
178
 
309
179
  private
310
180
 
181
+ def color_msg
182
+ [
183
+ "Whether or not to use ANSI color in the output. Cucumber decides",
184
+ "based on your platform and the output destination if not specified."
185
+ ]
186
+ end
187
+
188
+ def dry_run_msg
189
+ [
190
+ "Invokes formatters without executing the steps.",
191
+ "This also omits the loading of your support/env.rb file if it exists."
192
+ ]
193
+ end
194
+
195
+ def exclude_msg
196
+ [ "Don't run feature files or require ruby files matching PATTERN" ]
197
+ end
198
+
199
+ def format_msg
200
+ [ "How to format features (Default: pretty). Available formats:" ]
201
+ end
202
+
203
+ def i18n_msg
204
+ [
205
+ "List keywords for in a particular language",
206
+ %{Run with "--i18n help" to see all languages}
207
+ ]
208
+ end
209
+
210
+ def init_msg
211
+ [
212
+ 'Initializes folder structure and generates conventional files for',
213
+ 'a Cucumber project.'
214
+ ]
215
+ end
216
+
217
+ def lines_msg
218
+ [ "Run given line numbers. Equivalent to FILE:LINE syntax" ]
219
+ end
220
+
221
+ def no_profile_short_flag_msg
222
+ [
223
+ "Disables all profile loading to avoid using the 'default' profile."
224
+ ]
225
+ end
226
+
227
+ def profile_short_flag_msg
228
+ [
229
+ "Pull commandline arguments from cucumber.yml which can be defined as",
230
+ "strings or arrays. When a 'default' profile is defined and no profile",
231
+ "is specified it is always used. (Unless disabled, see -P below.)",
232
+ "When feature files are defined in a profile and on the command line",
233
+ "then only the ones from the command line are used."
234
+ ]
235
+ end
236
+
237
+ def retry_msg
238
+ [ "Specify the number of times to retry failing tests (default: 0)" ]
239
+ end
240
+
241
+ def name_msg
242
+ [
243
+ "Only execute the feature elements which match part of the given name.",
244
+ "If this option is given more than once, it will match against all the",
245
+ "given names."
246
+ ]
247
+ end
248
+
249
+ def set_out_stream(v)
250
+ @options[:formats] << ['pretty', nil] if @options[:formats].empty?
251
+ @options[:formats][-1][1] = v
252
+ end
253
+
254
+ def tags_msg
255
+ [
256
+ "Only execute the features or scenarios with tags matching TAG_EXPRESSION.",
257
+ "Scenarios inherit tags declared on the Feature level. The simplest",
258
+ "TAG_EXPRESSION is simply a tag. Example: --tags @dev. When a tag in a tag",
259
+ "expression starts with a ~, this represents boolean NOT. Example: --tags ~@dev.",
260
+ "A tag expression can have several tags separated by a comma, which represents",
261
+ "logical OR. Example: --tags @dev,@wip. The --tags option can be specified",
262
+ "several times, and this represents logical AND. Example: --tags @foo,~@bar --tags @zap.",
263
+ "This represents the boolean expression (@foo || !@bar) && @zap.",
264
+ "\n",
265
+ "Beware that if you want to use several negative tags to exclude several tags",
266
+ "you have to use logical AND: --tags ~@fixme --tags ~@buggy.",
267
+ "\n",
268
+ "Positive tags can be given a threshold to limit the number of occurrences.",
269
+ "Example: --tags @qa:3 will fail if there are more than 3 occurrences of the @qa tag.",
270
+ "This can be practical if you are practicing Kanban or CONWIP."
271
+ ]
272
+ end
273
+
274
+ def out_msg
275
+ [
276
+ "Write output to a file/directory instead of STDOUT. This option",
277
+ "applies to the previously specified --format, or the",
278
+ "default format if no format is specified. Check the specific",
279
+ "formatter's docs to see whether to pass a file or a dir."
280
+ ]
281
+ end
282
+
283
+ def require_files_msg
284
+ [
285
+ "Require files before executing the features. If this",
286
+ "option is not specified, all *.rb files that are",
287
+ "siblings or below the features will be loaded auto-",
288
+ "matically. Automatic loading is disabled when this",
289
+ "option is specified, and all loading becomes explicit.",
290
+ "Files under directories named \"support\" are always",
291
+ "loaded first.",
292
+ "This option can be specified multiple times."
293
+ ]
294
+ end
295
+
296
+ def snippet_type_msg
297
+ [
298
+ "Use different snippet type (Default: regexp). Available types:",
299
+ Cucumber::RbSupport::RbLanguage.cli_snippet_type_options
300
+ ].flatten
301
+ end
302
+
303
+ def banner
304
+ ["Usage: cucumber [options] [ [FILE|DIR|URL][:LINE[:LINE]*] ]+", "",
305
+ "Examples:",
306
+ "cucumber examples/i18n/en/features",
307
+ "cucumber @rerun.txt (See --format rerun)",
308
+ "cucumber examples/i18n/it/features/somma.feature:6:98:113",
309
+ "cucumber -s -i http://rubyurl.com/eeCl", "", "",
310
+ ].join("\n")
311
+ end
312
+
313
+ def require_files(v)
314
+ @options[:require] << v
315
+ if(Cucumber::JRUBY && File.directory?(v))
316
+ require 'java'
317
+ $CLASSPATH << v
318
+ end
319
+ end
320
+
321
+ def require_jars(jars)
322
+ Dir["#{jars}/**/*.jar"].each {|jar| require jar}
323
+ end
324
+
325
+ def set_language(lang)
326
+ require 'gherkin/dialect'
327
+
328
+ if lang == 'help'
329
+ list_languages_and_exit
330
+ elsif !::Gherkin::DIALECTS.keys.include? lang
331
+ indicate_invalid_language_and_exit(lang)
332
+ else
333
+ list_keywords_and_exit(lang)
334
+ end
335
+ end
336
+
337
+ def disable_profile_loading
338
+ @disable_profile_loading = true
339
+ end
340
+
311
341
  def non_stdout_formats
312
342
  @options[:formats].select {|format, output| output != @out_stream }
313
343
  end
314
344
 
345
+ def add_option(option, value)
346
+ @options[option] << value
347
+ end
348
+
349
+ def set_color(color)
350
+ Cucumber::Term::ANSIColor.coloring = color
351
+ end
352
+
353
+ def initialize_project
354
+ ProjectInitializer.new.run && Kernel.exit(0)
355
+ end
356
+
357
+ def add_profile(p)
358
+ @profiles << p
359
+ end
360
+
361
+ def set_option(option, value=nil)
362
+ @options[option] = value.nil? ? true : value
363
+ end
364
+
365
+ def set_dry_run_and_duration
366
+ @options[:dry_run] = true
367
+ @options[:duration] = false
368
+ end
369
+
370
+ def exit_ok(text)
371
+ @out_stream.puts text
372
+ Kernel.exit(0)
373
+ end
374
+
375
+ def shut_up
376
+ @options[:snippets] = false
377
+ @options[:source] = false
378
+ @options[:duration] = false
379
+ end
380
+
315
381
  def stdout_formats
316
382
  @options[:formats].select {|format, output| output == @out_stream }
317
383
  end