aslakhellesoy-cucumber 0.1.16.4 → 0.1.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/History.txt +75 -1
  2. data/Manifest.txt +58 -65
  3. data/examples/cs/features/step_definitons/calculator_steps.rb +1 -1
  4. data/examples/i18n/Rakefile +3 -3
  5. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +1 -6
  6. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +1 -1
  7. data/examples/i18n/de/features/addition.feature +6 -6
  8. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +2 -2
  9. data/examples/i18n/en/features/addition.feature +6 -6
  10. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +2 -2
  11. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +1 -1
  12. data/examples/i18n/et/features/liitmine.feature +7 -6
  13. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +1 -1
  14. data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +1 -1
  15. data/examples/i18n/fi/features/yhteenlasku.feature +2 -2
  16. data/examples/i18n/fr/features/addition.feature +2 -2
  17. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +1 -1
  18. data/examples/i18n/id/features/addition.feature +6 -6
  19. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +2 -2
  20. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +1 -1
  21. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +2 -3
  22. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +1 -1
  23. data/examples/i18n/lt/features/addition.feature +7 -6
  24. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +2 -2
  25. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +7 -7
  26. data/examples/i18n/no/features/summering.feature +1 -0
  27. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +1 -1
  28. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +1 -1
  29. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +1 -1
  30. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +2 -2
  31. data/examples/jbehave/README.textile +17 -0
  32. data/examples/jbehave/features/support/env.rb +7 -0
  33. data/examples/jbehave/features/trading.feature +24 -0
  34. data/examples/jbehave/pom.xml +48 -0
  35. data/examples/self_test/README.textile +4 -1
  36. data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
  37. data/examples/self_test/features/lots_of_undefined.feature +8 -0
  38. data/examples/self_test/features/outline_sample.feature +8 -5
  39. data/examples/self_test/features/sample.feature +5 -3
  40. data/examples/self_test/features/step_definitions/sample_steps.rb +15 -3
  41. data/features/cucumber_cli.feature +199 -97
  42. data/features/cucumber_cli_outlines.feature +46 -38
  43. data/features/report_called_undefined_steps.feature +31 -0
  44. data/features/step_definitions/cucumber_steps.rb +7 -3
  45. data/features/step_definitions/extra_steps.rb +1 -1
  46. data/features/support/env.rb +1 -1
  47. data/gem_tasks/features.rake +1 -1
  48. data/gem_tasks/flog.rake +1 -1
  49. data/lib/autotest/cucumber_mixin.rb +16 -23
  50. data/lib/cucumber/ast/comment.rb +26 -0
  51. data/lib/cucumber/ast/examples.rb +22 -0
  52. data/lib/cucumber/ast/feature.rb +60 -0
  53. data/lib/cucumber/ast/features.rb +39 -0
  54. data/lib/cucumber/ast/filter.rb +22 -0
  55. data/lib/cucumber/ast/outline_table.rb +49 -0
  56. data/lib/cucumber/ast/py_string.rb +52 -0
  57. data/lib/cucumber/ast/scenario.rb +91 -0
  58. data/lib/cucumber/ast/scenario_outline.rb +83 -0
  59. data/lib/cucumber/ast/step.rb +130 -0
  60. data/lib/cucumber/ast/table.rb +214 -0
  61. data/lib/cucumber/ast/tags.rb +33 -0
  62. data/lib/cucumber/ast/visitor.rb +93 -0
  63. data/lib/cucumber/ast.rb +27 -0
  64. data/lib/cucumber/broadcaster.rb +1 -6
  65. data/lib/cucumber/cli.rb +178 -128
  66. data/lib/cucumber/core_ext/exception.rb +41 -8
  67. data/lib/cucumber/core_ext/instance_exec.rb +54 -0
  68. data/lib/cucumber/core_ext/proc.rb +29 -65
  69. data/lib/cucumber/core_ext/string.rb +19 -0
  70. data/lib/cucumber/{formatters → formatter}/ansicolor.rb +11 -10
  71. data/lib/cucumber/formatter/console.rb +116 -0
  72. data/lib/cucumber/formatter/pretty.rb +158 -0
  73. data/lib/cucumber/formatter/profile.rb +77 -0
  74. data/lib/cucumber/formatter/progress.rb +68 -0
  75. data/lib/cucumber/formatter.rb +1 -0
  76. data/lib/cucumber/formatters/autotest_formatter.rb +0 -2
  77. data/lib/cucumber/formatters/html_formatter.rb +4 -3
  78. data/lib/cucumber/formatters/pretty_formatter.rb +1 -1
  79. data/lib/cucumber/formatters/unicode.rb +3 -3
  80. data/lib/cucumber/jbehave.rb +104 -0
  81. data/lib/cucumber/languages.yml +100 -73
  82. data/lib/cucumber/parser/basic.rb +0 -0
  83. data/lib/cucumber/parser/feature.rb +1694 -0
  84. data/lib/cucumber/parser/feature.tt +206 -0
  85. data/lib/cucumber/parser/file_parser.rb +50 -0
  86. data/lib/cucumber/parser/i18n.tt +26 -0
  87. data/lib/cucumber/parser/treetop_ext.rb +9 -0
  88. data/lib/cucumber/parser.rb +27 -0
  89. data/lib/cucumber/platform.rb +3 -17
  90. data/lib/cucumber/step_definition.rb +83 -0
  91. data/lib/cucumber/step_mother.rb +128 -72
  92. data/lib/cucumber/version.rb +1 -1
  93. data/lib/cucumber.rb +56 -9
  94. data/spec/cucumber/ast/feature_factory.rb +54 -0
  95. data/spec/cucumber/ast/feature_spec.rb +60 -0
  96. data/spec/cucumber/ast/py_string_spec.rb +40 -0
  97. data/spec/cucumber/ast/scenario_outline_spec.rb +64 -0
  98. data/spec/cucumber/ast/scenario_spec.rb +82 -0
  99. data/spec/cucumber/ast/step_spec.rb +45 -0
  100. data/spec/cucumber/ast/table_spec.rb +81 -0
  101. data/spec/cucumber/broadcaster_spec.rb +4 -17
  102. data/spec/cucumber/cli_spec.rb +43 -148
  103. data/spec/cucumber/core_ext/proc_spec.rb +27 -35
  104. data/spec/cucumber/core_ext/string_spec.rb +8 -0
  105. data/spec/cucumber/{formatters → formatter}/ansicolor_spec.rb +2 -2
  106. data/spec/cucumber/formatter/html/cucumber.css +37 -0
  107. data/spec/cucumber/formatter/html/cucumber.js +11 -0
  108. data/spec/cucumber/formatter/html/index.html +45 -0
  109. data/spec/cucumber/formatter/html/jquery-1.3.min.js +19 -0
  110. data/spec/cucumber/formatter/html/jquery.uitableedit.js +100 -0
  111. data/spec/cucumber/formatters/autotest_formatter_spec.rb +1 -0
  112. data/spec/cucumber/formatters/profile_formatter_spec.rb +17 -16
  113. data/spec/cucumber/parser/feature_parser_spec.rb +247 -0
  114. data/spec/cucumber/parser/table_parser_spec.rb +48 -0
  115. data/spec/cucumber/step_definition_spec.rb +62 -0
  116. data/spec/cucumber/step_mom_spec.rb +49 -0
  117. data/spec/cucumber/treetop_parser/empty_feature.feature +1 -1
  118. data/spec/cucumber/treetop_parser/spaces.feature +3 -1
  119. data/spec/cucumber/treetop_parser/with_comments.feature +1 -1
  120. data/spec/cucumber/treetop_parser/with_tags.feature +18 -0
  121. data/spec/cucumber/world/pending_spec.rb +13 -12
  122. data/spec/spec_helper.rb +1 -1
  123. metadata +59 -67
  124. data/examples/calculator_ruby_features/Rakefile +0 -6
  125. data/examples/calculator_ruby_features/features/addition.rb +0 -39
  126. data/examples/calculator_ruby_features/features/step_definitons/calculator_steps.rb +0 -43
  127. data/gem_tasks/treetop.rake +0 -41
  128. data/lib/cucumber/executor.rb +0 -205
  129. data/lib/cucumber/formatters/profile_formatter.rb +0 -92
  130. data/lib/cucumber/formatters/progress_formatter.rb +0 -61
  131. data/lib/cucumber/formatters.rb +0 -1
  132. data/lib/cucumber/model/table.rb +0 -32
  133. data/lib/cucumber/model.rb +0 -1
  134. data/lib/cucumber/step_methods.rb +0 -49
  135. data/lib/cucumber/tree/feature.rb +0 -105
  136. data/lib/cucumber/tree/features.rb +0 -21
  137. data/lib/cucumber/tree/given_scenario.rb +0 -13
  138. data/lib/cucumber/tree/scenario.rb +0 -240
  139. data/lib/cucumber/tree/step.rb +0 -173
  140. data/lib/cucumber/tree/table.rb +0 -26
  141. data/lib/cucumber/tree/top_down_visitor.rb +0 -23
  142. data/lib/cucumber/tree.rb +0 -16
  143. data/lib/cucumber/treetop_parser/feature.treetop.erb +0 -254
  144. data/lib/cucumber/treetop_parser/feature_ar.rb +0 -1951
  145. data/lib/cucumber/treetop_parser/feature_cy.rb +0 -1951
  146. data/lib/cucumber/treetop_parser/feature_da.rb +0 -1951
  147. data/lib/cucumber/treetop_parser/feature_de.rb +0 -1951
  148. data/lib/cucumber/treetop_parser/feature_en-lol.rb +0 -1951
  149. data/lib/cucumber/treetop_parser/feature_en-tx.rb +0 -1951
  150. data/lib/cucumber/treetop_parser/feature_en.rb +0 -1951
  151. data/lib/cucumber/treetop_parser/feature_es.rb +0 -1951
  152. data/lib/cucumber/treetop_parser/feature_et.rb +0 -1951
  153. data/lib/cucumber/treetop_parser/feature_fr.rb +0 -1951
  154. data/lib/cucumber/treetop_parser/feature_id.rb +0 -1951
  155. data/lib/cucumber/treetop_parser/feature_it.rb +0 -1951
  156. data/lib/cucumber/treetop_parser/feature_ja.rb +0 -1951
  157. data/lib/cucumber/treetop_parser/feature_ko.rb +0 -1951
  158. data/lib/cucumber/treetop_parser/feature_lt.rb +0 -1951
  159. data/lib/cucumber/treetop_parser/feature_nl.rb +0 -1951
  160. data/lib/cucumber/treetop_parser/feature_no.rb +0 -1951
  161. data/lib/cucumber/treetop_parser/feature_parser.rb +0 -36
  162. data/lib/cucumber/treetop_parser/feature_pl.rb +0 -1951
  163. data/lib/cucumber/treetop_parser/feature_pt.rb +0 -1951
  164. data/lib/cucumber/treetop_parser/feature_ro.rb +0 -1951
  165. data/lib/cucumber/treetop_parser/feature_ro2.rb +0 -1951
  166. data/lib/cucumber/treetop_parser/feature_ru.rb +0 -1951
  167. data/lib/cucumber/treetop_parser/feature_se.rb +0 -1951
  168. data/lib/cucumber/treetop_parser/feature_zh-CN.rb +0 -1951
  169. data/lib/cucumber/world/pending.rb +0 -22
  170. data/lib/cucumber/world.rb +0 -1
  171. data/setup.rb +0 -1585
  172. data/spec/cucumber/executor_spec.rb +0 -382
  173. data/spec/cucumber/formatters/html_formatter_spec.rb +0 -104
  174. data/spec/cucumber/formatters/pretty_formatter_spec.rb +0 -410
  175. data/spec/cucumber/formatters/progress_formatter_spec.rb +0 -81
  176. data/spec/cucumber/model/table_spec.rb +0 -32
  177. data/spec/cucumber/step_mother_spec.rb +0 -74
  178. data/spec/cucumber/tree/feature_spec.rb +0 -122
  179. data/spec/cucumber/tree/row_scenario_outline_spec.rb +0 -73
  180. data/spec/cucumber/tree/row_scenario_spec.rb +0 -55
  181. data/spec/cucumber/tree/row_step_outline_spec.rb +0 -38
  182. data/spec/cucumber/tree/scenario_outline_spec.rb +0 -50
  183. data/spec/cucumber/tree/scenario_spec.rb +0 -134
  184. data/spec/cucumber/tree/step_outline_spec.rb +0 -17
  185. data/spec/cucumber/tree/step_spec.rb +0 -59
  186. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +0 -120
data/lib/cucumber/cli.rb CHANGED
@@ -1,16 +1,22 @@
1
1
  require 'optparse'
2
2
  require 'cucumber'
3
3
  require 'ostruct'
4
+ require 'cucumber/parser'
5
+ require 'cucumber/formatter'
4
6
 
5
7
  module Cucumber
6
8
  class YmlLoadError < StandardError; end
7
9
 
8
10
  class CLI
9
11
  class << self
10
- attr_writer :step_mother, :executor, :features
12
+ def step_mother=(step_mother)
13
+ @step_mother = step_mother
14
+ @step_mother.extend(StepMother)
15
+ @step_mother.snippet_generator = StepDefinition
16
+ end
11
17
 
12
18
  def execute(args)
13
- parse(args).execute!(@step_mother, @executor, @features)
19
+ parse(args).execute!(@step_mother)
14
20
  end
15
21
 
16
22
  def parse(args)
@@ -26,17 +32,18 @@ module Cucumber
26
32
 
27
33
  def initialize(out_stream = STDOUT, error_stream = STDERR)
28
34
  @out_stream = out_stream
35
+
29
36
  @error_stream = error_stream
30
37
  @paths = []
31
38
  @options = {
32
- :require => nil,
33
- :lang => 'en',
34
- :dry_run => false,
35
- :source => true,
36
- :snippets => true,
37
- :formats => {},
39
+ :strict => false,
40
+ :require => nil,
41
+ :lang => 'en',
42
+ :dry_run => false,
43
+ :formats => {},
38
44
  :excludes => [],
39
- :scenario_names => nil
45
+ :tags => [],
46
+ :scenario_names => []
40
47
  }
41
48
  @active_format = DEFAULT_FORMAT
42
49
  end
@@ -52,143 +59,156 @@ module Cucumber
52
59
  "cucumber examples/i18n/en/features",
53
60
  "cucumber --language it examples/i18n/it/features/somma.feature:6:98:113", "", ""
54
61
  ].join("\n")
55
- opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR", "Require files before executing the features.",
56
- "If this option is not specified, all *.rb files that",
57
- "are siblings or below the features will be autorequired",
62
+ opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR",
63
+ "Require files before executing the features. If this",
64
+ "option is not specified, all *.rb files that are",
65
+ "siblings or below the features will be loaded auto-",
66
+ "matically. Automatic loading is disabled when this",
67
+ "option is specified, and all loading becomes explicit.",
68
+ "Files under directories named \"support\" are always",
69
+ "loaded first.",
58
70
  "This option can be specified multiple times.") do |v|
59
71
  @options[:require] ||= []
60
72
  @options[:require] << v
61
73
  end
62
- opts.on("-s SCENARIO", "--scenario SCENARIO", "Only execute the scenario with the given name.",
63
- "If this option is given more than once, run all",
64
- "the specified scenarios.") do |v|
65
- @options[:scenario_names] ||= []
66
- @options[:scenario_names] << v
67
- end
68
- opts.on("-l LANG", "--language LANG", "Specify language for features (Default: #{@options[:lang]})",
69
- "Available languages: #{Cucumber.languages.join(", ")}",
70
- "Look at #{Cucumber::LANGUAGE_FILE} for keywords") do |v|
71
- @options[:lang] = v
74
+ opts.on("-l LANG", "--language LANG",
75
+ "Specify language for features (Default: #{@options[:lang]})",
76
+ %{Run with "--language help" to see all languages},
77
+ %{Run with "--language LANG help" to list keywords for LANG}) do |v|
78
+ if v == 'help'
79
+ list_languages
80
+ elsif args==['help']
81
+ list_keywords('en', v)
82
+ else
83
+ @options[:lang] = v
84
+ end
72
85
  end
73
- opts.on("-f FORMAT", "--format FORMAT", "How to format features (Default: #{DEFAULT_FORMAT})",
86
+ opts.on("-f FORMAT", "--format FORMAT",
87
+ "How to format features (Default: #{DEFAULT_FORMAT})",
74
88
  "Available formats: #{FORMATS.join(", ")}",
75
- "You can also provide your own formatter classes as long as they have been",
76
- "previously required using --require or if they are in the folder",
77
- "structure such that cucumber will require them automatically.",
89
+ "You can also provide your own formatter classes as long",
90
+ "as they have been previously required using --require or",
91
+ "if they are in the folder structure such that cucumber",
92
+ "will require them automatically.",
78
93
  "This option can be specified multiple times.") do |v|
79
-
80
- @options[:formats][v] ||= []
81
- @options[:formats][v] << @out_stream
94
+ @options[:formats][v] = @out_stream
82
95
  @active_format = v
83
96
  end
84
- opts.on("-o", "--out FILE", "Write output to a file instead of @out_stream.",
85
- "This option can be specified multiple times, and applies to the previously",
86
- "specified --format.") do |v|
87
- @options[:formats][@active_format] ||= []
88
- if @options[:formats][@active_format].last == @out_stream
89
- @options[:formats][@active_format][-1] = File.open(v, 'w')
90
- else
91
- @options[:formats][@active_format] << File.open(v, 'w')
92
- end
97
+ opts.on("-o", "--out FILE",
98
+ "Write output to a file instead of STDOUT. This option",
99
+ "applies to the previously specified --format, or the",
100
+ "default format if no format is specified.") do |v|
101
+ @options[:formats][@active_format] = v
102
+ end
103
+ opts.on("-t TAGS", "--tags TAGS",
104
+ "Only execute the features or scenarios with the specified tags.",
105
+ "TAGS must be comma-separated without spaces.") do |v|
106
+ @options[:tags] = v.split(",")
93
107
  end
94
- opts.on("-c", "--[no-]color", "Use ANSI color in the output, if formatters use it. If",
95
- "these options are given multiple times, the last one is",
96
- "used. If neither --color or --no-color is given cucumber",
97
- "decides based on your platform and the output destination") do |v|
98
- @options[:color] = v
108
+ opts.on("-s SCENARIO", "--scenario SCENARIO",
109
+ "Only execute the scenario with the given name. If this option",
110
+ "is given more than once, run all the specified scenarios.") do |v|
111
+ @options[:scenario_names] << v
99
112
  end
100
- opts.on("-e", "--exclude PATTERN", "Don't run features matching a pattern") do |v|
113
+ opts.on("-e", "--exclude PATTERN", "Don't run feature files matching PATTERN") do |v|
101
114
  @options[:excludes] << v
102
115
  end
103
116
  opts.on("-p", "--profile PROFILE", "Pull commandline arguments from cucumber.yml.") do |v|
104
117
  parse_args_from_profile(v)
105
118
  end
106
- opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.") do
119
+ opts.on("-c", "--[no-]color",
120
+ "Whether or not to use ANSI color in the output. Cucumber decides",
121
+ "based on your platform and the output destination if not specified.") do |v|
122
+ Term::ANSIColor.coloring = v
123
+ end
124
+ opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.",
125
+ "Implies --quiet.") do
126
+ @options[:dry_run] = true
127
+ @quiet = true
128
+ end
129
+ opts.on("-a", "--autoformat DIRECTORY",
130
+ "Reformats (pretty prints) feature files and write them to DIRECTORY.",
131
+ "Be careful if you choose to overwrite the originals.",
132
+ "Implies --dry-run --formatter pretty.") do |directory|
133
+ @options[:autoformat] = directory
134
+ Term::ANSIColor.coloring = false
107
135
  @options[:dry_run] = true
136
+ @quiet = true
108
137
  end
109
- opts.on("-n", "--no-source", "Don't show the file and line of the step definition with the steps.") do
110
- @options[:source] = false
138
+ opts.on("-n", "--[no-]source",
139
+ "Don't show the file and line of the step definition with the steps.") do |v|
140
+ @options[:source] = v
111
141
  end
112
- opts.on("-i", "--no-snippets", "Don't show the snippets for pending steps") do
113
- @options[:snippets] = false
142
+ opts.on("-i", "--[no-]snippets", "Don't show the snippets for pending steps.") do |v|
143
+ @options[:snippets] = v
114
144
  end
115
- opts.on("-q", "--quiet", "Don't show any development aid information") do
116
- @options[:snippets] = false
117
- @options[:source] = false
145
+ opts.on("-q", "--quiet", "Alias for --no-snippets --no-source.") do
146
+ @quiet = true
118
147
  end
119
- opts.on("-b", "--backtrace", "Show full backtrace for all errors") do
148
+ opts.on("-b", "--backtrace", "Show full backtrace for all errors.") do
120
149
  Exception.cucumber_full_backtrace = true
121
150
  end
122
- opts.on("-v", "--verbose", "Show the files and features loaded") do
151
+ opts.on("--strict", "Fail if there are any undefined or pending steps.") do
152
+ @options[:strict] = true
153
+ end
154
+ opts.on("-v", "--verbose", "Show the files and features loaded.") do
123
155
  @options[:verbose] = true
124
156
  end
125
- opts.on_tail("--version", "Show version") do
157
+ opts.on_tail("--version", "Show version.") do
126
158
  @out_stream.puts VERSION::STRING
127
159
  Kernel.exit
128
160
  end
129
- opts.on_tail("--help", "You're looking at it") do
161
+ opts.on_tail("--help", "You're looking at it.") do
130
162
  @out_stream.puts opts.help
131
163
  Kernel.exit
132
164
  end
133
165
  end.parse!
134
166
 
135
- if @options[:formats].empty?
136
- @options[:formats][DEFAULT_FORMAT] = [@out_stream]
137
- end
138
-
167
+ @options[:formats]['pretty'] = @out_stream if @options[:formats].empty?
168
+
169
+ @options[:snippets] = true if !@quiet && @options[:snippets].nil?
170
+ @options[:source] = true if !@quiet && @options[:source].nil?
171
+
139
172
  # Whatever is left after option parsing is the FILE arguments
140
- args = extract_and_store_line_numbers(args)
141
173
  @paths += args
142
174
  end
143
175
 
144
176
 
145
- def execute!(step_mother, executor, features)
146
- Term::ANSIColor.coloring = @options[:color] unless @options[:color].nil?
177
+ def execute!(step_mother)
147
178
  Cucumber.load_language(@options[:lang])
148
179
  require_files
149
180
  enable_diffing
150
- executor.formatters = build_formatter_broadcaster(step_mother)
151
- load_plain_text_features(features)
152
- executor.lines_for_features = @options[:lines_for_features]
153
- executor.dry_run = @options[:dry_run] if @options[:dry_run]
154
- executor.scenario_names = @options[:scenario_names] if @options[:scenario_names]
155
- executor.visit_features(features)
156
- exit 1 if executor.failed
181
+ features = load_plain_text_features
182
+
183
+ visitor = build_formatter_broadcaster(step_mother)
184
+ visitor.options = @options
185
+ visitor.visit_features(features)
186
+ exit_code = features.steps[:failed].length
187
+ exit_code += (features.steps[:undefined].length + features.steps[:pending].length) if @options[:strict]
188
+ Kernel.exit(exit_code)
157
189
  end
158
190
 
159
191
  private
160
192
 
161
- def extract_and_store_line_numbers(file_arguments)
162
- @options[:lines_for_features] = Hash.new{|k,v| k[v] = []}
163
- file_arguments.map do |arg|
164
- _, file, lines = */^([\w\W]*?):([\d:]+)$/.match(arg)
165
- unless file.nil?
166
- @options[:lines_for_features][file] += lines.split(':').map { |line| line.to_i }
167
- arg = file
168
- end
169
- arg
170
- end
171
- end
172
-
173
193
  def cucumber_yml
174
194
  return @cucumber_yml if @cucumber_yml
175
195
  unless File.exist?('cucumber.yml')
176
196
  raise(YmlLoadError,"cucumber.yml was not found. Please refer to cucumber's documentaion on defining profiles in cucumber.yml. You must define a 'default' profile to use the cucumber command without any arguments.\nType 'cucumber --help' for usage.\n")
177
197
  end
178
-
198
+
179
199
  require 'yaml'
180
200
  begin
181
201
  @cucumber_yml = YAML::load(IO.read('cucumber.yml'))
182
202
  rescue Exception => e
183
203
  raise(YmlLoadError,"cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentaion on correct profile usage.\n")
184
- end
185
-
204
+ end
205
+
186
206
  if @cucumber_yml.nil? || !@cucumber_yml.is_a?(Hash)
187
207
  raise(YmlLoadError,"cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentaion on correct profile usage.\n")
188
208
  end
189
209
 
190
210
  return @cucumber_yml
191
- end
211
+ end
192
212
 
193
213
  def parse_args_from_profile(profile)
194
214
  unless cucumber_yml.has_key?(profile)
@@ -209,7 +229,7 @@ Defined profiles in cucumber.yml:
209
229
  else
210
230
  parse_options!(args_from_yml.split(' '))
211
231
  end
212
-
232
+
213
233
  rescue YmlLoadError => e
214
234
  exit_with_error(e.message)
215
235
  end
@@ -218,8 +238,6 @@ Defined profiles in cucumber.yml:
218
238
  # Requires files - typically step files and ruby feature files.
219
239
  def require_files
220
240
  @args.clear # Shut up RSpec
221
- require "cucumber/treetop_parser/feature_#{@options[:lang]}"
222
- require "cucumber/treetop_parser/feature_parser"
223
241
 
224
242
  verbose_log("Ruby files required:")
225
243
  files_to_require.each do |lib|
@@ -233,7 +251,7 @@ Defined profiles in cucumber.yml:
233
251
  end
234
252
  verbose_log("\n")
235
253
  end
236
-
254
+
237
255
  def files_to_require
238
256
  requires = @options[:require] || feature_dirs
239
257
  files = requires.map do |path|
@@ -263,57 +281,52 @@ Defined profiles in cucumber.yml:
263
281
  feature_files.map{|f| File.directory?(f) ? f : File.dirname(f)}.uniq
264
282
  end
265
283
 
266
- def load_plain_text_features(features)
267
- parser = TreetopParser::FeatureParser.new
284
+ def load_plain_text_features
285
+ filter = Ast::Filter.new(@options)
286
+ features = Ast::Features.new(filter)
287
+ parser = Parser::FeatureParser.new
268
288
 
269
289
  verbose_log("Features:")
270
290
  feature_files.each do |f|
271
- features << parser.parse_feature(f)
291
+ features.add_feature(parser.parse_file(f))
272
292
  verbose_log(" * #{f}")
273
293
  end
274
294
  verbose_log("\n"*2)
295
+ features
275
296
  end
276
297
 
277
298
  def build_formatter_broadcaster(step_mother)
278
- formatter_broadcaster = Broadcaster.new
279
- @options[:formats].each do |format, output_list|
280
- output_broadcaster = build_output_broadcaster(output_list)
299
+ return Formatter::Pretty.new(step_mother, nil, @options) if @options[:autoformat]
300
+ formatters = @options[:formats].map do |format, out|
301
+ if String === out # file name
302
+ out = File.open(out, Cucumber.file_mode('w'))
303
+ at_exit do
304
+ out.flush
305
+ out.close
306
+ end
307
+ end
308
+
281
309
  case format
282
310
  when 'pretty'
283
- formatter_broadcaster.register(Formatters::PrettyFormatter.new(output_broadcaster, step_mother, @options))
311
+ Formatter::Pretty.new(step_mother, out, @options)
284
312
  when 'progress'
285
- formatter_broadcaster.register(Formatters::ProgressFormatter.new(output_broadcaster))
313
+ Formatter::Progress.new(step_mother, out, @options)
286
314
  when 'profile'
287
- formatter_broadcaster.register(Formatters::ProfileFormatter.new(output_broadcaster, step_mother))
288
- when 'html'
289
- formatter_broadcaster.register(Formatters::HtmlFormatter.new(output_broadcaster, step_mother))
290
- when 'autotest'
291
- formatter_broadcaster.register(Formatters::AutotestFormatter.new(output_broadcaster))
315
+ Formatter::Profile.new(step_mother, out, @options)
316
+ when 'rerun'
317
+ Formatter::Rerun.new(step_mother, out, @options)
292
318
  else
293
319
  begin
294
320
  formatter_class = constantize(format)
295
- formatter_broadcaster.register(formatter_class.new(output_broadcaster, step_mother, @options))
296
- rescue NameError => e
297
- @error_stream.puts "Invalid format: #{format}\n"
298
- exit_with_help
321
+ formatter_class.new(step_mother, out, @options)
299
322
  rescue Exception => e
300
- exit_with_error("Error creating formatter: #{format}\n#{e}\n")
323
+ exit_with_error("Error creating formatter: #{format}", e)
301
324
  end
302
325
  end
303
326
  end
304
- formatter_broadcaster
327
+ Broadcaster.new(formatters)
305
328
  end
306
329
 
307
- def build_output_broadcaster(output_list)
308
- output_broadcaster = Broadcaster.new
309
- output_list.each do |output|
310
- output_broadcaster.register(output)
311
- end
312
- output_broadcaster
313
- end
314
-
315
- private
316
-
317
330
  def constantize(camel_cased_word)
318
331
  names = camel_cased_word.split('::')
319
332
  names.shift if names.empty? || names.first.empty?
@@ -324,7 +337,7 @@ Defined profiles in cucumber.yml:
324
337
  end
325
338
  constant
326
339
  end
327
-
340
+
328
341
  def verbose_log(string)
329
342
  @out_stream.puts(string) if @options[:verbose]
330
343
  end
@@ -333,8 +346,12 @@ Defined profiles in cucumber.yml:
333
346
  parse_options!(%w{--help})
334
347
  end
335
348
 
336
- def exit_with_error(error_message)
337
- @error_stream << error_message
349
+ def exit_with_error(error_message, e=nil)
350
+ @error_stream.puts(error_message)
351
+ if e
352
+ @error_stream.puts("#{e.message} (#{e.class})")
353
+ @error_stream.puts(e.backtrace.join("\n"))
354
+ end
338
355
  Kernel.exit 1
339
356
  end
340
357
 
@@ -345,12 +362,45 @@ Defined profiles in cucumber.yml:
345
362
  ::Spec::Expectations.differ = ::Spec::Expectations::Differs::Default.new(options)
346
363
  end
347
364
  end
365
+
366
+ def list_languages
367
+ raw = Cucumber::LANGUAGES.keys.sort.map do |lang|
368
+ [lang, Cucumber::LANGUAGES[lang]['name'], Cucumber::LANGUAGES[lang]['native']]
369
+ end
370
+ print_table(raw)
371
+ end
372
+
373
+ def list_keywords(ref, lang)
374
+ unless Cucumber::LANGUAGES[lang]
375
+ exit_with_error("No language with key #{v}")
376
+ end
377
+ Cucumber.load_language(lang)
378
+ raw = %w{feature background scenario scenario_outline examples given when then but}.map do |key|
379
+ [Cucumber::LANGUAGES[ref][key], Cucumber::LANGUAGES[lang][key]]
380
+ end
381
+ print_table(raw)
382
+ end
383
+
384
+ def print_table(raw)
385
+ table = Ast::Table.new(raw)
386
+ formatter = Formatter::Pretty.new(nil, @out_stream, {}, '')
387
+
388
+ def formatter.visit_table_row(table_row, status)
389
+ @col = 1
390
+ super
391
+ end
392
+
393
+ def formatter.visit_table_cell_value(value, width, status)
394
+ status = :comment if @col == 1
395
+ @col += 1
396
+ super(value, width, status)
397
+ end
398
+
399
+ formatter.indent = 0
400
+ formatter.visit_multiline_arg(table, :passed)
401
+ Kernel.exit
402
+ end
348
403
  end
349
404
  end
350
405
 
351
- extend Cucumber::StepMethods
352
- Cucumber::CLI.step_mother = step_mother
353
- Cucumber::CLI.executor = executor
354
-
355
- extend Cucumber::Tree
356
- Cucumber::CLI.features = features
406
+ Cucumber::CLI.step_mother = self
@@ -1,20 +1,53 @@
1
+ # Exception extension that tweaks Exception backtraces:
2
+ #
3
+ # * The line of the failing .feature line is appended to the backtrace
4
+ # * The line that calls #cucumber_instance_exec is replaced with the StepDefinition's regexp
5
+ # * Non intersting lines are stripped out
6
+ #
7
+ # The result is that backtraces look like this:
8
+ #
9
+ # features/step_definitions/the_step_definition.rb:in `/some step/'
10
+ # features/the_feature_file.feature:41:in `Given some step'
11
+ #
12
+ # or if the exception is raised in the tested code:
13
+ #
14
+ # lib/myapp/some_file.rb:in `/some_method/'
15
+ # lib/myapp/some_other_file.rb:in `/some_other_method/'
16
+ # features/step_definitions/the_step_definition.rb:in `/some step/'
17
+ # features/the_feature_file.feature:41:in `Given some step'
18
+ #
19
+ # All backtrace munging can be turned off with the <tt>--backtrace</tt> switch
20
+ #
1
21
  class Exception
2
22
  CUCUMBER_FILTER_PATTERNS = [
3
- /vendor\/rails/,
4
- /vendor\/plugins\/cucumber/,
5
- /vendor\/plugins\/rspec/,
6
- /gems\/rspec/
23
+ /vendor\/rails|lib\/cucumber|lib\/rspec|gems\//
7
24
  ]
8
25
 
26
+ INSTANCE_EXEC_OFFSET = (Cucumber::RUBY_1_9 || Cucumber::JRUBY) ? -3 : -4
27
+
9
28
  def self.cucumber_full_backtrace=(v)
10
29
  @@cucumber_full_backtrace = v
11
30
  end
12
31
  self.cucumber_full_backtrace = false
13
32
 
14
- def cucumber_backtrace
15
- return (backtrace || []) if @@cucumber_full_backtrace
16
- (backtrace || []).map {|b| b.split("\n") }.flatten.reject do |line|
33
+ # Strips the backtrace from +line+ and down
34
+ def self.cucumber_strip_backtrace!(backtrace, instance_exec_invocation_line, pseudo_method)
35
+ return if @@cucumber_full_backtrace
36
+
37
+ instance_exec_pos = backtrace.index(instance_exec_invocation_line)
38
+ if instance_exec_pos
39
+ replacement_line = instance_exec_pos + INSTANCE_EXEC_OFFSET
40
+ backtrace[replacement_line].gsub!(/`.*'/, "`#{pseudo_method}'") if pseudo_method
41
+ backtrace[replacement_line+1..-1] = nil
42
+
43
+ backtrace.compact!
44
+ else
45
+ # This happens with rails, because they screw up the backtrace
46
+ # before we get here (injecting erb stacktrace and such)
47
+ end
48
+
49
+ backtrace.reject! do |line|
17
50
  CUCUMBER_FILTER_PATTERNS.detect{|p| line =~ p}
18
- end.map { |line| line.strip }
51
+ end
19
52
  end
20
53
  end
@@ -0,0 +1,54 @@
1
+ require 'cucumber/platform'
2
+
3
+ module Cucumber
4
+ class ArityMismatchError < StandardError
5
+ end
6
+ end
7
+
8
+ class Object
9
+ def cucumber_instance_exec(check_arity, pseudo_method, *args, &block)
10
+ arity = block.arity
11
+ arity = 0 if arity == -1
12
+ cucumber_run_with_backtrace_filtering(pseudo_method) do
13
+ if check_arity && args.length != arity
14
+ instance_exec do
15
+ raise Cucumber::ArityMismatchError.new("expected #{arity} block argument(s), got #{args.length}")
16
+ end
17
+ else
18
+ instance_exec(*args, &block)
19
+ end
20
+ end
21
+ end
22
+
23
+ def cucumber_run_with_backtrace_filtering(pseudo_method)
24
+ begin
25
+ yield
26
+ rescue Exception => e
27
+ instance_exec_invocation_line = "#{__FILE__}:#{__LINE__ - 2}:in `cucumber_run_with_backtrace_filtering'"
28
+ Exception.cucumber_strip_backtrace!((e.backtrace || []), instance_exec_invocation_line, pseudo_method)
29
+ raise e
30
+ end
31
+ end
32
+
33
+ unless defined? instance_exec # 1.9
34
+ # http://eigenclass.org/hiki/bounded+space+instance_exec
35
+ module InstanceExecHelper; end
36
+ include InstanceExecHelper
37
+ def instance_exec(*args, &block)
38
+ begin
39
+ old_critical, Thread.critical = Thread.critical, true
40
+ n = 0
41
+ n += 1 while respond_to?(mname="__instance_exec#{n}")
42
+ InstanceExecHelper.module_eval{ define_method(mname, &block) }
43
+ ensure
44
+ Thread.critical = old_critical
45
+ end
46
+ begin
47
+ ret = send(mname, *args)
48
+ ensure
49
+ InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
50
+ end
51
+ ret
52
+ end
53
+ end
54
+ end