cucumber 0.3.96 → 0.3.97

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +22 -3
  2. data/License.txt +2 -0
  3. data/Manifest.txt +9 -5
  4. data/config/hoe.rb +1 -0
  5. data/examples/i18n/Rakefile +5 -3
  6. data/examples/i18n/fi/features/yhteenlasku.feature +5 -4
  7. data/examples/python/features/step_definitions/fib_steps.py +3 -0
  8. data/examples/python/features/support/env.rb +21 -21
  9. data/gem_tasks/contributors.rake +8 -0
  10. data/gem_tasks/features.rake +1 -0
  11. data/gem_tasks/sdoc.rake +7 -0
  12. data/lib/README.rdoc +12 -0
  13. data/lib/cucumber/ast/background.rb +1 -1
  14. data/lib/cucumber/ast/comment.rb +1 -1
  15. data/lib/cucumber/ast/examples.rb +9 -4
  16. data/lib/cucumber/ast/feature.rb +1 -1
  17. data/lib/cucumber/ast/feature_element.rb +1 -1
  18. data/lib/cucumber/ast/features.rb +1 -1
  19. data/lib/cucumber/ast/outline_table.rb +2 -2
  20. data/lib/cucumber/ast/py_string.rb +1 -1
  21. data/lib/cucumber/ast/scenario.rb +1 -1
  22. data/lib/cucumber/ast/scenario_outline.rb +8 -7
  23. data/lib/cucumber/ast/step.rb +1 -1
  24. data/lib/cucumber/ast/step_collection.rb +1 -1
  25. data/lib/cucumber/ast/step_invocation.rb +1 -1
  26. data/lib/cucumber/ast/table.rb +65 -45
  27. data/lib/cucumber/ast/tags.rb +2 -2
  28. data/lib/cucumber/ast/visitor.rb +6 -8
  29. data/lib/cucumber/broadcaster.rb +1 -1
  30. data/lib/cucumber/cli/language_help_formatter.rb +1 -1
  31. data/lib/cucumber/cli/main.rb +15 -52
  32. data/lib/cucumber/constantize.rb +1 -1
  33. data/lib/cucumber/core_ext/exception.rb +1 -1
  34. data/lib/cucumber/core_ext/instance_exec.rb +8 -3
  35. data/lib/cucumber/core_ext/proc.rb +1 -1
  36. data/lib/cucumber/core_ext/string.rb +1 -1
  37. data/lib/cucumber/feature_file.rb +4 -3
  38. data/lib/cucumber/filter.rb +2 -1
  39. data/lib/cucumber/formatter/ansicolor.rb +6 -5
  40. data/lib/cucumber/formatter/color_io.rb +2 -2
  41. data/lib/cucumber/formatter/console.rb +2 -0
  42. data/lib/cucumber/formatter/duration.rb +3 -0
  43. data/lib/cucumber/formatter/html.rb +1 -0
  44. data/lib/cucumber/formatter/junit.rb +1 -0
  45. data/lib/cucumber/formatter/ordered_xml_markup.rb +1 -1
  46. data/lib/cucumber/formatter/pretty.rb +18 -4
  47. data/lib/cucumber/formatter/profile.rb +1 -0
  48. data/lib/cucumber/formatter/progress.rb +1 -0
  49. data/lib/cucumber/formatter/rerun.rb +2 -0
  50. data/lib/cucumber/formatter/steps.rb +1 -0
  51. data/lib/cucumber/formatter/tag_cloud.rb +2 -1
  52. data/lib/cucumber/formatter/unicode.rb +1 -1
  53. data/lib/cucumber/formatter/usage.rb +1 -0
  54. data/lib/cucumber/language_support.rb +30 -0
  55. data/lib/cucumber/language_support/language_methods.rb +34 -12
  56. data/lib/cucumber/parser/feature.rb +81 -57
  57. data/lib/cucumber/parser/feature.tt +3 -3
  58. data/lib/cucumber/parser/natural_language.rb +1 -1
  59. data/lib/cucumber/parser/table.rb +3 -0
  60. data/lib/cucumber/parser/treetop_ext.rb +6 -5
  61. data/lib/cucumber/platform.rb +1 -2
  62. data/lib/cucumber/py_support/py_dsl.py +8 -0
  63. data/lib/cucumber/py_support/py_language.py +2 -0
  64. data/lib/cucumber/py_support/py_language.rb +68 -0
  65. data/lib/cucumber/rails/world.rb +2 -1
  66. data/lib/cucumber/rake/task.rb +13 -11
  67. data/lib/cucumber/rb_support/rb_dsl.rb +27 -15
  68. data/lib/cucumber/rb_support/rb_hook.rb +1 -2
  69. data/lib/cucumber/rb_support/rb_language.rb +57 -33
  70. data/lib/cucumber/rb_support/rb_step_definition.rb +42 -38
  71. data/lib/cucumber/rb_support/rb_world.rb +93 -0
  72. data/lib/cucumber/rspec_neuter.rb +3 -3
  73. data/lib/cucumber/step_match.rb +2 -2
  74. data/lib/cucumber/step_mother.rb +91 -65
  75. data/lib/cucumber/version.rb +1 -1
  76. data/lib/cucumber/webrat/element_locator.rb +3 -3
  77. data/rails_generators/cucumber/templates/cucumber.rake +2 -0
  78. data/rails_generators/cucumber/templates/webrat_steps.rb +4 -0
  79. data/spec/cucumber/ast/background_spec.rb +8 -1
  80. data/spec/cucumber/ast/scenario_outline_spec.rb +1 -0
  81. data/spec/cucumber/ast/table_spec.rb +10 -0
  82. data/spec/cucumber/cli/options_spec.rb +1 -1
  83. data/spec/cucumber/parser/feature_parser_spec.rb +4 -0
  84. data/spec/cucumber/rb_support/rb_step_definition_spec.rb +114 -0
  85. data/spec/cucumber/step_mother_spec.rb +29 -10
  86. data/spec/cucumber/treetop_parser/with_comments.feature +14 -1
  87. data/spec/cucumber/world/pending_spec.rb +1 -1
  88. metadata +21 -7
  89. data/gem_tasks/yard.rake +0 -8
  90. data/lib/cucumber/language_support/hook_methods.rb +0 -9
  91. data/lib/cucumber/world.rb +0 -89
  92. data/spec/cucumber/ast/visitor_spec.rb +0 -27
  93. data/spec/cucumber/step_definition_spec.rb +0 -102
@@ -1,6 +1,7 @@
1
1
  module Cucumber
2
2
  module Formatter
3
- # Custom formatter that prints a tag cloud
3
+ # The formatter used for <tt>--format tag_cloud</tt>
4
+ # Custom formatter that prints a tag cloud as a table.
4
5
  class TagCloud < Cucumber::Ast::Visitor
5
6
  def initialize(step_mother, io, options)
6
7
  super(step_mother)
@@ -12,7 +12,7 @@ if Cucumber::WINDOWS_MRI && `chcp` =~ /(\d+)/
12
12
  Cucumber::CODEPAGE = "cp#{codepage}"
13
13
 
14
14
  require 'iconv'
15
- module Kernel
15
+ module Kernel #:nodoc:
16
16
  alias cucumber_print print
17
17
  def print(*a)
18
18
  begin
@@ -2,6 +2,7 @@ require 'cucumber/formatter/progress'
2
2
 
3
3
  module Cucumber
4
4
  module Formatter
5
+ # The formatter used for <tt>--format usage</tt>
5
6
  class Usage < Ast::Visitor
6
7
  include Console
7
8
 
@@ -0,0 +1,30 @@
1
+ module Cucumber
2
+ # This module defines the API for programming panguage support in Cucumber.
3
+ # While Cucumber itself is written in Ruby, any programming language can
4
+ # be supported by implementing this API.
5
+ #
6
+ # For the sake of illustration we'll consider an imaginary language called
7
+ # _why. _why files have the .why extension, so we need to put support for
8
+ # this language in the <tt>Cucumber::WhySupport::WhyLanguage</tt>. This
9
+ # class must be defined in a file called <tt>cucumber/why_support/why_language.rb</tt>
10
+ # and be available on Ruby's <tt>$LOAD_PATH</tt>:
11
+ #
12
+ # module Cucumber
13
+ # module WhySupport
14
+ # class WhyLanguage
15
+ #
16
+ # # Uses whatever available language bridge to load
17
+ # # +why_file+ and returns an Array of StepDefinition.
18
+ # def load_code_file(why_file)
19
+ # end
20
+ # end
21
+ # end
22
+ # end
23
+ #
24
+ # Each language implementation manages its own hooks, and must execute them
25
+ # at appropriate times.
26
+ #
27
+ #
28
+ module LanguageSupport
29
+ end
30
+ end
@@ -2,35 +2,57 @@ module Cucumber
2
2
  module LanguageSupport
3
3
  module LanguageMethods
4
4
  def before(scenario)
5
- step_mother.begin_scenario
5
+ begin_scenario
6
6
  execute_before(scenario)
7
7
  end
8
8
 
9
9
  def after(scenario)
10
10
  execute_after(scenario)
11
- step_mother.end_scenario
11
+ end_scenario
12
+ end
13
+
14
+ def execute_after_step(scenario)
15
+ hooks_for(:after_step, scenario).each do |hook|
16
+ invoke(hook, 'AfterStep', scenario, false)
17
+ end
18
+ end
19
+
20
+ def add_hook(phase, hook)
21
+ hooks[phase.to_sym] << hook
22
+ hook
23
+ end
24
+
25
+ def add_step_definition(step_definition)
26
+ step_definitions << step_definition
27
+ step_definition
28
+ end
29
+
30
+ def step_definitions
31
+ @step_definitions ||= []
32
+ end
33
+
34
+ def hooks_for(phase, scenario) #:nodoc:
35
+ hooks[phase.to_sym].select{|hook| scenario.accept_hook?(hook)}
36
+ end
37
+
38
+ private
39
+
40
+ def hooks
41
+ @hooks ||= Hash.new{|h,k| h[k] = []}
12
42
  end
13
43
 
14
44
  def execute_before(scenario)
15
- step_mother.hooks_for(:before, scenario).each do |hook|
45
+ hooks_for(:before, scenario).each do |hook|
16
46
  invoke(hook, 'Before', scenario, true)
17
47
  end
18
48
  end
19
49
 
20
50
  def execute_after(scenario)
21
- step_mother.hooks_for(:after, scenario).each do |hook|
51
+ hooks_for(:after, scenario).each do |hook|
22
52
  invoke(hook, 'After', scenario, true)
23
53
  end
24
54
  end
25
55
 
26
- def execute_after_step(scenario)
27
- step_mother.hooks_for(:after_step, scenario).each do |hook|
28
- invoke(hook, 'AfterStep', scenario, false)
29
- end
30
- end
31
-
32
- private
33
-
34
56
  def invoke(hook, location, scenario, exception_fails_scenario)
35
57
  begin
36
58
  hook.invoke(location, scenario)
@@ -1,3 +1,6 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
1
4
  module Cucumber
2
5
  module Parser
3
6
  # TIP: When you hack on the grammar, just delete feature.rb in this directory.
@@ -17,7 +20,7 @@ module Cucumber
17
20
  end
18
21
 
19
22
  module FeatureSub1
20
- def white
23
+ def white1
21
24
  elements[0]
22
25
  end
23
26
 
@@ -25,7 +28,7 @@ module Cucumber
25
28
  elements[1]
26
29
  end
27
30
 
28
- def white
31
+ def white2
29
32
  elements[2]
30
33
  end
31
34
 
@@ -33,7 +36,7 @@ module Cucumber
33
36
  elements[3]
34
37
  end
35
38
 
36
- def white
39
+ def white3
37
40
  elements[4]
38
41
  end
39
42
 
@@ -424,7 +427,7 @@ module Cucumber
424
427
 
425
428
  module CommentLine0
426
429
  def line_to_eol
427
- elements[1]
430
+ elements[2]
428
431
  end
429
432
  end
430
433
 
@@ -437,17 +440,30 @@ module Cucumber
437
440
  end
438
441
 
439
442
  i0, s0 = index, []
440
- if has_terminal?('#', false, index)
441
- r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
442
- @index += 1
443
- else
444
- terminal_parse_failure('#')
445
- r1 = nil
443
+ s1, i1 = [], index
444
+ loop do
445
+ r2 = _nt_space
446
+ if r2
447
+ s1 << r2
448
+ else
449
+ break
450
+ end
446
451
  end
452
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
447
453
  s0 << r1
448
454
  if r1
449
- r2 = _nt_line_to_eol
450
- s0 << r2
455
+ if has_terminal?('#', false, index)
456
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
457
+ @index += 1
458
+ else
459
+ terminal_parse_failure('#')
460
+ r3 = nil
461
+ end
462
+ s0 << r3
463
+ if r3
464
+ r4 = _nt_line_to_eol
465
+ s0 << r4
466
+ end
451
467
  end
452
468
  if s0.last
453
469
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
@@ -664,7 +680,7 @@ module Cucumber
664
680
  elements[1]
665
681
  end
666
682
 
667
- def white
683
+ def white1
668
684
  elements[2]
669
685
  end
670
686
 
@@ -676,7 +692,7 @@ module Cucumber
676
692
  elements[5]
677
693
  end
678
694
 
679
- def white
695
+ def white2
680
696
  elements[6]
681
697
  end
682
698
 
@@ -684,7 +700,7 @@ module Cucumber
684
700
  elements[7]
685
701
  end
686
702
 
687
- def white
703
+ def white3
688
704
  elements[8]
689
705
  end
690
706
  end
@@ -798,7 +814,7 @@ module Cucumber
798
814
  elements[1]
799
815
  end
800
816
 
801
- def white
817
+ def white1
802
818
  elements[2]
803
819
  end
804
820
 
@@ -810,7 +826,7 @@ module Cucumber
810
826
  elements[5]
811
827
  end
812
828
 
813
- def white
829
+ def white2
814
830
  elements[6]
815
831
  end
816
832
 
@@ -822,7 +838,7 @@ module Cucumber
822
838
  elements[8]
823
839
  end
824
840
 
825
- def white
841
+ def white3
826
842
  elements[9]
827
843
  end
828
844
  end
@@ -1154,24 +1170,28 @@ module Cucumber
1154
1170
  end
1155
1171
 
1156
1172
  module Examples0
1173
+ def comment
1174
+ elements[0]
1175
+ end
1176
+
1157
1177
  def examples_keyword
1158
- elements[1]
1178
+ elements[2]
1159
1179
  end
1160
1180
 
1161
1181
  def name
1162
- elements[3]
1182
+ elements[4]
1163
1183
  end
1164
1184
 
1165
1185
  def eol
1166
- elements[4]
1186
+ elements[5]
1167
1187
  end
1168
1188
 
1169
1189
  def table
1170
- elements[5]
1190
+ elements[6]
1171
1191
  end
1172
1192
 
1173
1193
  def white
1174
- elements[6]
1194
+ elements[7]
1175
1195
  end
1176
1196
  end
1177
1197
 
@@ -1198,7 +1218,7 @@ module Cucumber
1198
1218
  end
1199
1219
 
1200
1220
  def build(filter, scenario_outline)
1201
- [examples_keyword.line, examples_keyword.text_value, name.build, table.raw(filter, scenario_outline)]
1221
+ [comment.build, examples_keyword.line, examples_keyword.text_value, name.build, table.raw(filter, scenario_outline)]
1202
1222
  end
1203
1223
  end
1204
1224
 
@@ -1211,49 +1231,53 @@ module Cucumber
1211
1231
  end
1212
1232
 
1213
1233
  i0, s0 = index, []
1214
- s1, i1 = [], index
1215
- loop do
1216
- r2 = _nt_space
1217
- if r2
1218
- s1 << r2
1219
- else
1220
- break
1221
- end
1222
- end
1223
- r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
1234
+ r1 = _nt_comment
1224
1235
  s0 << r1
1225
1236
  if r1
1226
- r3 = _nt_examples_keyword
1227
- s0 << r3
1228
- if r3
1229
- s4, i4 = [], index
1230
- loop do
1231
- r5 = _nt_space
1232
- if r5
1233
- s4 << r5
1234
- else
1235
- break
1236
- end
1237
+ s2, i2 = [], index
1238
+ loop do
1239
+ r3 = _nt_space
1240
+ if r3
1241
+ s2 << r3
1242
+ else
1243
+ break
1237
1244
  end
1238
- r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1245
+ end
1246
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1247
+ s0 << r2
1248
+ if r2
1249
+ r4 = _nt_examples_keyword
1239
1250
  s0 << r4
1240
1251
  if r4
1241
- r7 = _nt_lines_to_keyword
1242
- if r7
1243
- r6 = r7
1244
- else
1245
- r6 = instantiate_node(SyntaxNode,input, index...index)
1252
+ s5, i5 = [], index
1253
+ loop do
1254
+ r6 = _nt_space
1255
+ if r6
1256
+ s5 << r6
1257
+ else
1258
+ break
1259
+ end
1246
1260
  end
1247
- s0 << r6
1248
- if r6
1249
- r8 = _nt_eol
1250
- s0 << r8
1261
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
1262
+ s0 << r5
1263
+ if r5
1264
+ r8 = _nt_lines_to_keyword
1251
1265
  if r8
1252
- r9 = _nt_table
1266
+ r7 = r8
1267
+ else
1268
+ r7 = instantiate_node(SyntaxNode,input, index...index)
1269
+ end
1270
+ s0 << r7
1271
+ if r7
1272
+ r9 = _nt_eol
1253
1273
  s0 << r9
1254
1274
  if r9
1255
- r10 = _nt_white
1275
+ r10 = _nt_table
1256
1276
  s0 << r10
1277
+ if r10
1278
+ r11 = _nt_white
1279
+ s0 << r11
1280
+ end
1257
1281
  end
1258
1282
  end
1259
1283
  end
@@ -78,7 +78,7 @@ module Cucumber
78
78
  end
79
79
 
80
80
  rule comment_line
81
- '#' line_to_eol
81
+ space* '#' line_to_eol
82
82
  end
83
83
 
84
84
  rule background
@@ -262,7 +262,7 @@ module Cucumber
262
262
  end
263
263
 
264
264
  rule examples
265
- space* examples_keyword space* name:lines_to_keyword? eol table white {
265
+ comment space* examples_keyword space* name:lines_to_keyword? eol table white {
266
266
  def at_line?(line)
267
267
  examples_keyword.line == line ||
268
268
  table.at_line?(line)
@@ -285,7 +285,7 @@ module Cucumber
285
285
  end
286
286
 
287
287
  def build(filter, scenario_outline)
288
- [examples_keyword.line, examples_keyword.text_value, name.build, table.raw(filter, scenario_outline)]
288
+ [comment.build, examples_keyword.line, examples_keyword.text_value, name.build, table.raw(filter, scenario_outline)]
289
289
  end
290
290
  }
291
291
  end
@@ -22,7 +22,7 @@ module Cucumber
22
22
 
23
23
  def register_adverbs(step_mother)
24
24
  adverbs = %w{given when then and but}.map{|keyword| @keywords[keyword].split('|').map{|w| w.gsub(/\s/, '')}}.flatten
25
- step_mother.register_adverbs(adverbs)
25
+ step_mother.register_adverbs(adverbs) if step_mother
26
26
  end
27
27
 
28
28
  def parser
@@ -1,3 +1,6 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
1
4
  module Cucumber
2
5
  module Parser
3
6
  # TIP: When you hack on the grammar, just delete feature.rb in this directory.
@@ -12,6 +12,7 @@ end
12
12
 
13
13
  module Cucumber
14
14
  module Parser
15
+ # Raised if Cucumber fails to parse a feature file
15
16
  class SyntaxError < StandardError
16
17
  def initialize(parser, file, line_offset)
17
18
  tf = parser.terminal_failures
@@ -22,7 +23,7 @@ module Cucumber
22
23
  end
23
24
  end
24
25
 
25
- module TreetopExt
26
+ module TreetopExt #:nodoc:
26
27
  def parse_or_fail(source, file=nil, filter=nil, line_offset=0)
27
28
  parse_tree = parse(source)
28
29
  if parse_tree.nil?
@@ -37,15 +38,15 @@ module Cucumber
37
38
  end
38
39
  end
39
40
 
40
- module Treetop
41
- module Runtime
42
- class SyntaxNode
41
+ module Treetop #:nodoc:
42
+ module Runtime #:nodoc:
43
+ class SyntaxNode #:nodoc:
43
44
  def line
44
45
  input.line_of(interval.first)
45
46
  end
46
47
  end
47
48
 
48
- class CompiledParser
49
+ class CompiledParser #:nodoc:
49
50
  include Cucumber::Parser::TreetopExt
50
51
  end
51
52
  end