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
@@ -1,13 +1,13 @@
1
1
  require 'autotest'
2
2
  require 'tempfile'
3
- require File.dirname(__FILE__) + '/../cucumber/platform'
3
+ require File.dirname(__FILE__) + '/../cucumber'
4
4
 
5
5
  module Autotest::CucumberMixin
6
6
  def self.included(receiver)
7
7
  receiver::ALL_HOOKS << [:run_features, :ran_features]
8
8
  end
9
9
 
10
- attr_accessor :scenarios_to_run
10
+ attr_accessor :features_to_run
11
11
 
12
12
  def initialize
13
13
  super
@@ -45,7 +45,7 @@ module Autotest::CucumberMixin
45
45
  end
46
46
 
47
47
  def all_features_good
48
- scenarios_to_run == []
48
+ features_to_run == ""
49
49
  end
50
50
 
51
51
  def get_to_green
@@ -62,13 +62,13 @@ module Autotest::CucumberMixin
62
62
  end
63
63
 
64
64
  def reset_features
65
- self.scenarios_to_run = :all
65
+ self.features_to_run = :all
66
66
  end
67
67
 
68
68
  def run_features
69
69
  hook :run_features
70
- Tempfile.open('autotest-cucumber') do |dirty_scenarios_file|
71
- cmd = self.make_cucumber_cmd self.scenarios_to_run, dirty_scenarios_file.path
70
+ Tempfile.open('autotest-cucumber') do |dirty_features_file|
71
+ cmd = self.make_cucumber_cmd(self.features_to_run, dirty_features_file.path)
72
72
  return if cmd.empty?
73
73
  puts cmd unless $q
74
74
  old_sync = $stdout.sync
@@ -94,37 +94,30 @@ module Autotest::CucumberMixin
94
94
  ensure
95
95
  $stdout.sync = old_sync
96
96
  end
97
- self.scenarios_to_run = dirty_scenarios_file.readlines.map { |l| l.chomp }
98
- self.tainted = true unless self.scenarios_to_run == []
97
+ self.features_to_run = dirty_features_file.read
98
+ self.tainted = true unless self.features_to_run == []
99
99
  end
100
100
  hook :ran_features
101
101
  end
102
102
 
103
- def make_cucumber_cmd(scenarios_to_run, dirty_scenarios_filename)
104
- return '' if scenarios_to_run == []
103
+ def make_cucumber_cmd(features_to_run, dirty_features_filename)
104
+ return '' if features_to_run == ''
105
105
 
106
106
  profiles = YAML.load_file("cucumber.yml").keys rescue []
107
107
 
108
- profile ||= "autotest-all" if profiles.include?("autotest-all") and scenarios_to_run == :all
108
+ profile ||= "autotest-all" if profiles.include?("autotest-all") and features_to_run == :all
109
109
  profile ||= "autotest" if profiles.include?("autotest")
110
110
  profile ||= nil
111
111
 
112
112
  if profile
113
113
  args = ["--profile", profile]
114
114
  else
115
- args = %w{features --format} << (scenarios_to_run == :all ? "progress" : "pretty")
115
+ args = %w{--format} << (features_to_run == :all ? "progress" : "pretty")
116
116
  end
117
- args += %w{--format autotest --color --out} << dirty_scenarios_filename
117
+ args += %w{--color --format rerun --out} << dirty_features_filename
118
+ args << (features_to_run == :all ? "features" : features_to_run)
118
119
  args = args.join(' ')
119
-
120
- if scenarios_to_run == :all
121
- scenario_args = nil
122
- else
123
- # We escape scenario names for the shell by wrapping them in $'...' and replacing
124
- # every single quote with an escaped version, "\'". We use a double backslash for
125
- # Ruby, and we put it in a block or gsub interpolates the sequence "\'" as $'.
126
- scenario_args = scenarios_to_run.map { |s| "-s $'#{s.gsub("'") {"\\'"} }'" }.join(' ')
127
- end
128
- return "#{Cucumber::RUBY_BINARY} #{Cucumber::BINARY} #{args} #{scenario_args}"
120
+
121
+ return "#{Cucumber::RUBY_BINARY} #{Cucumber::BINARY} #{args}"
129
122
  end
130
123
  end
@@ -0,0 +1,26 @@
1
+ module Cucumber
2
+ module Ast
3
+ # Holds the value of a comment parsed from a feature file:
4
+ #
5
+ # # Lorem ipsum
6
+ # # dolor sit amet
7
+ #
8
+ # This gets parsed into a Comment with value <tt>"# Lorem ipsum\n# dolor sit amet\n"</tt>
9
+ #
10
+ class Comment
11
+ def initialize(value)
12
+ @value = value
13
+ end
14
+
15
+ def accept(visitor)
16
+ @value.split("\n").each do |line|
17
+ visitor.visit_comment_line(line.strip)
18
+ end
19
+ end
20
+
21
+ def to_sexp
22
+ (@value.nil? || @value == '') ? nil : [:comment, @value]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Examples
4
+ def initialize(line, keyword, name, outline_table)
5
+ @keyword, @name, @outline_table = keyword, name, outline_table
6
+ end
7
+
8
+ def accept(visitor)
9
+ visitor.visit_examples_name(@keyword, @name)
10
+ @outline_table.accept(visitor, nil)
11
+ end
12
+
13
+ def at_lines?(lines)
14
+ lines.empty? || lines.index(@line) || @outline_table.at_lines?(lines)
15
+ end
16
+
17
+ def to_sexp
18
+ [:examples, @keyword, @name, @outline_table.to_sexp]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,60 @@
1
+ module Cucumber
2
+ module Ast
3
+ # Represents the root node of a parsed feature.
4
+ class Feature
5
+ attr_accessor :file
6
+ attr_writer :features, :lines
7
+
8
+ def initialize(comment, tags, name, feature_elements)
9
+ @comment, @tags, @name, @feature_elements = comment, tags, name, feature_elements
10
+ feature_elements.each{|feature_element| feature_element.feature = self}
11
+ @lines = []
12
+ end
13
+
14
+ def tagged_with?(tag_names, check_elements=true)
15
+ @tags.among?(tag_names) ||
16
+ (check_elements && @feature_elements.detect{|e| e.tagged_with?(tag_names)})
17
+ end
18
+
19
+ def matches_scenario_names?(scenario_names)
20
+ @feature_elements.detect{|e| e.matches_scenario_names?(scenario_names)}
21
+ end
22
+
23
+ def accept(visitor)
24
+ visitor.current_feature_lines = @lines
25
+ visitor.visit_comment(@comment)
26
+ visitor.visit_tags(@tags)
27
+ visitor.visit_feature_name(@name)
28
+ @feature_elements.each do |feature_element|
29
+ visitor.visit_feature_element(feature_element) if @features.visit?(feature_element, @lines)
30
+ end
31
+ end
32
+
33
+ def scenario_executed(scenario)
34
+ @features.scenario_executed(scenario) if @features
35
+ end
36
+
37
+ def step_executed(step)
38
+ @features.step_executed(step) if @features
39
+ end
40
+
41
+ def backtrace_line(step_name, line)
42
+ "#{file_line(line)}:in `#{step_name}'"
43
+ end
44
+
45
+ def file_line(line)
46
+ "#{@file}:#{line}"
47
+ end
48
+
49
+ def to_sexp
50
+ sexp = [:feature, @name]
51
+ comment = @comment.to_sexp
52
+ sexp += [comment] if comment
53
+ tags = @tags.to_sexp
54
+ sexp += tags if tags.any?
55
+ sexp += @feature_elements.map{|e| e.to_sexp}
56
+ sexp
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Features
4
+ attr_reader :steps, :scenarios
5
+
6
+ def initialize(filter)
7
+ @filter = filter
8
+
9
+ @features = []
10
+ @scenarios = []
11
+ @steps = Hash.new{|steps, status| steps[status] = []}
12
+ end
13
+
14
+ def add_feature(feature)
15
+ feature.features = self
16
+ @features << feature
17
+ end
18
+
19
+ def visit?(node, lines)
20
+ @filter.matched?(node) &&
21
+ (lines.empty? ? true : node.at_lines?(lines))
22
+ end
23
+
24
+ def scenario_executed(scenario)
25
+ @scenarios << scenario
26
+ end
27
+
28
+ def step_executed(step)
29
+ @steps[step.status] << step
30
+ end
31
+
32
+ def accept(visitor)
33
+ @features.each do |feature|
34
+ visitor.visit_feature(feature) if visit?(feature, [])
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Filter
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def matched?(node)
9
+ matched_by_tags?(node) &&
10
+ matched_by_scenario_names?(node)
11
+ end
12
+
13
+ def matched_by_tags?(node)
14
+ @options[:tags].empty? || node.tagged_with?(@options[:tags])
15
+ end
16
+
17
+ def matched_by_scenario_names?(node)
18
+ @options[:scenario_names].empty? || node.matches_scenario_names?(@options[:scenario_names])
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ module Cucumber
2
+ module Ast
3
+ class OutlineTable < Table
4
+ def initialize(raw, scenario_outline)
5
+ super(raw)
6
+ @scenario_outline = scenario_outline
7
+ @cells_class = ExampleCells
8
+ end
9
+
10
+ def accept(visitor, status)
11
+ rows.each_with_index do |row, n|
12
+ should_visit = n == 0 ||
13
+ row.at_lines?(visitor.current_feature_lines) ||
14
+ @scenario_outline.at_header_or_step_lines?(visitor.current_feature_lines)
15
+
16
+ if should_visit
17
+ visitor.visit_table_row(row, status)
18
+ end
19
+ end
20
+ nil
21
+ end
22
+
23
+ def execute_row(cells, visitor, &proc)
24
+ @scenario_outline.execute_row(cells, visitor, &proc)
25
+ end
26
+
27
+ class ExampleCells < Cells
28
+ def accept(visitor, status)
29
+ if header?
30
+ @cells.each do |cell|
31
+ visitor.visit_table_cell(cell, :thead)
32
+ end
33
+ nil
34
+ else
35
+ exception = @table.execute_row(self, visitor) do |cell, status|
36
+ visitor.visit_table_cell(cell, status)
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def header?
44
+ index == 0
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,52 @@
1
+ module Cucumber
2
+ module Ast
3
+ # Represents an inline argument in a step. Example:
4
+ #
5
+ # Given the message
6
+ # """
7
+ # I like
8
+ # Cucumber sandwich
9
+ # """
10
+ #
11
+ # The text between the pair of <tt>"""</tt> is stored inside a PyString,
12
+ # which is yielded to the StepDefinition block as the last argument.
13
+ #
14
+ # The StepDefinition can then access the String via the #to_s method. In the
15
+ # example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
16
+ #
17
+ # Note how the indentation from the source is stripped away.
18
+ #
19
+ class PyString
20
+ def initialize(start_line, end_line, string, quotes_indent)
21
+ @start_line, @end_line = start_line, end_line
22
+ @string, @quotes_indent = string, quotes_indent
23
+ end
24
+
25
+ def to_s
26
+ @string.indent(-@quotes_indent)
27
+ end
28
+
29
+ def at_lines?(lines)
30
+ lines.detect{|l| l >= @start_line && l <= @end_line}
31
+ end
32
+
33
+ def accept(visitor, status)
34
+ visitor.visit_py_string(to_s, status)
35
+ end
36
+
37
+ def arguments_replaced(arguments) #:nodoc:
38
+ string = @string
39
+ arguments.each do |name, value|
40
+ string = string.gsub(name, value)
41
+ end
42
+ PyString.new(@start_line, @end_line, string, @quotes_indent)
43
+ end
44
+
45
+ # For testing only
46
+ def to_sexp #:nodoc:
47
+ [:py_string, to_s]
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,91 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Scenario
4
+ attr_writer :feature
5
+
6
+ def initialize(comment, tags, line, keyword, name, steps)
7
+ @comment, @tags, @line, @keyword, @name = comment, tags, line, keyword, name
8
+ steps.each {|step| step.scenario = self}
9
+ @steps = steps
10
+ end
11
+
12
+ def tagged_with?(tag_names)
13
+ @tags.among?(tag_names) || @feature.tagged_with?(tag_names, false)
14
+ end
15
+
16
+ def matches_scenario_names?(scenario_names)
17
+ scenario_names.detect{|name| @name == name}
18
+ end
19
+
20
+ def accept(visitor)
21
+ visitor.visit_comment(@comment)
22
+ visitor.visit_tags(@tags)
23
+ visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
24
+ visitor.world(self) do |world|
25
+ previous = :passed
26
+ @steps.each do |step|
27
+ step.previous = previous
28
+ step.world = world
29
+ visitor.visit_step(step)
30
+ previous = step.status
31
+ end
32
+ end
33
+ @feature.scenario_executed(self) if @feature && !@executed
34
+ @executed = true
35
+ end
36
+
37
+ def source_indent(text_length)
38
+ max_line_length - text_length
39
+ end
40
+
41
+ def max_line_length
42
+ lengths = (@steps + [self]).map{|e| e.text_length}
43
+ lengths.max
44
+ end
45
+
46
+ def text_length
47
+ @keyword.jlength + @name.jlength
48
+ end
49
+
50
+ def at_lines?(lines)
51
+ at_header_or_step_lines?(lines)
52
+ end
53
+
54
+ def at_header_or_step_lines?(lines)
55
+ lines.empty? || lines.index(@line) || @steps.detect {|step| step.at_lines?(lines)} || @tags.at_lines?(lines)
56
+ end
57
+
58
+ def undefined?
59
+ @steps.empty?
60
+ end
61
+
62
+ def step_executed(step)
63
+ @feature.step_executed(step) if @feature
64
+ end
65
+
66
+ def backtrace_line(name = "#{@keyword} #{@name}", line = @line)
67
+ @feature.backtrace_line(name, line) if @feature
68
+ end
69
+
70
+ def file_line(line = @line)
71
+ @feature.file_line(line) if @feature
72
+ end
73
+
74
+ def previous_step(step)
75
+ i = @steps.index(step)
76
+ @steps[i-1]
77
+ end
78
+
79
+ def to_sexp
80
+ sexp = [:scenario, @line, @keyword, @name]
81
+ comment = @comment.to_sexp
82
+ sexp += [comment] if comment
83
+ tags = @tags.to_sexp
84
+ sexp += tags if tags.any?
85
+ steps = @steps.map{|step| step.to_sexp}
86
+ sexp += steps if steps.any?
87
+ sexp
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,83 @@
1
+ module Cucumber
2
+ module Ast
3
+ class ScenarioOutline < Scenario
4
+ # The +example_sections+ argument must be an Array where each element is another array representing
5
+ # an Examples section. This array has 3 elements:
6
+ #
7
+ # * Examples keyword
8
+ # * Examples section name
9
+ # * Raw matrix
10
+ def initialize(comment, tags, line, keyword, name, steps, example_sections)
11
+ super(comment, tags, line, keyword, name, steps)
12
+ steps.each {|step| step.status = :outline}
13
+
14
+ @examples_array = example_sections.map do |example_section|
15
+ examples_line = example_section[0]
16
+ examples_keyword = example_section[1]
17
+ examples_name = example_section[2]
18
+ examples_matrix = example_section[3]
19
+
20
+ examples_table = OutlineTable.new(examples_matrix, self)
21
+ Examples.new(examples_line, examples_keyword, examples_name, examples_table)
22
+ end
23
+ end
24
+
25
+ def at_lines?(lines)
26
+ super || @examples_array.detect { |examples| examples.at_lines?(lines) }
27
+ end
28
+
29
+ def accept(visitor)
30
+ visitor.visit_comment(@comment)
31
+ visitor.visit_tags(@tags)
32
+ visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
33
+ @steps.each do |step|
34
+ visitor.visit_step(step)
35
+ end
36
+ @examples_array.each do |examples|
37
+ visitor.visit_examples(examples)
38
+ end
39
+ end
40
+
41
+ def execute_row(cells, visitor, &proc)
42
+ exception = nil
43
+ visitor.world(self) do |world|
44
+ previous_status = :passed
45
+ argument_hash = cells.to_hash
46
+ cell_index = 0
47
+ @steps.each do |step|
48
+ executed_step, previous_status, matched_args =
49
+ step.execute_with_arguments(argument_hash, world, previous_status, visitor, cells[0].line)
50
+ # There might be steps that don't have any arguments
51
+ # If there are no matched args, we'll still iterate once
52
+ matched_args = [nil] if matched_args.empty?
53
+
54
+ matched_args.each do
55
+ cell = cells[cell_index]
56
+ if cell
57
+ proc.call(cell, previous_status)
58
+ cell_index += 1
59
+ end
60
+ end
61
+ exception ||= executed_step.exception
62
+ end
63
+ end
64
+ @feature.scenario_executed(self) if @feature
65
+ exception
66
+ end
67
+
68
+ def pending? ; false ; end
69
+
70
+ def to_sexp
71
+ sexp = [:scenario_outline, @keyword, @name]
72
+ comment = @comment.to_sexp
73
+ sexp += [comment] if comment
74
+ tags = @tags.to_sexp
75
+ sexp += tags if tags.any?
76
+ steps = @steps.map{|step| step.to_sexp}
77
+ sexp += steps if steps.any?
78
+ sexp += @examples_array.map{|e| e.to_sexp}
79
+ sexp
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,130 @@
1
+ require 'cucumber/step_definition'
2
+ require 'cucumber/core_ext/string'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ class Step
7
+ attr_reader :keyword, :name
8
+ attr_writer :world, :previous, :options
9
+ attr_accessor :status, :scenario, :exception
10
+
11
+ def initialize(line, keyword, name, *multiline_args)
12
+ @line, @keyword, @name, @multiline_args = line, keyword, name, multiline_args
13
+ end
14
+
15
+ def execute_with_arguments(argument_hash, world, previous, visitor, row_line)
16
+ delimited_arguments = delimit_argument_names(argument_hash)
17
+ name = replace_name_arguments(delimited_arguments)
18
+ multiline_args = replace_multiline_args_arguments(delimited_arguments)
19
+
20
+ execute_twin(world, previous, visitor, row_line, name, *multiline_args)
21
+ end
22
+
23
+ def accept(visitor)
24
+ execute(visitor)
25
+ visitor.visit_step_name(@keyword, @name, @status, @step_definition, source_indent)
26
+ @multiline_args.each do |multiline_arg|
27
+ visitor.visit_multiline_arg(multiline_arg, @status)
28
+ end
29
+ @exception
30
+ end
31
+
32
+ def to_sexp
33
+ [:step, @line, @keyword, @name, *@multiline_args.map{|arg| arg.to_sexp}]
34
+ end
35
+
36
+ def at_lines?(lines)
37
+ lines.empty? || lines.index(@line) || @multiline_args.detect{|a| a.at_lines?(lines)}
38
+ end
39
+
40
+ def source_indent
41
+ @scenario.source_indent(text_length)
42
+ end
43
+
44
+ def text_length
45
+ @keyword.jlength + @name.jlength + 2 # Add 2 because steps get indented 2 more than scenarios
46
+ end
47
+
48
+ def backtrace_line
49
+ @backtrace_line ||= @scenario.backtrace_line("#{@keyword} #{@name}", @line) unless @scenario.nil?
50
+ end
51
+
52
+ def file_line
53
+ @file_line ||= @scenario.file_line(@line) unless @scenario.nil?
54
+ end
55
+
56
+ def actual_keyword
57
+ if [Cucumber.keyword_hash['and'], Cucumber.keyword_hash['but']].index(@keyword) && previous_step
58
+ previous_step.actual_keyword
59
+ else
60
+ @keyword
61
+ end
62
+ end
63
+
64
+ protected
65
+
66
+ def previous_step
67
+ @scenario.previous_step(self)
68
+ end
69
+
70
+ private
71
+
72
+ def execute(visitor)
73
+ matched_args = []
74
+ if @status.nil?
75
+ begin
76
+ @step_definition = visitor.step_definition(@name)
77
+ matched_args = @step_definition.matched_args(@name)
78
+ if @previous == :passed && !visitor.options[:dry_run]
79
+ @world.__cucumber_current_step = self
80
+ @step_definition.execute(@name, @world, *(matched_args + @multiline_args))
81
+ @status = :passed
82
+ else
83
+ @status = :skipped
84
+ end
85
+ rescue StepMother::Undefined
86
+ @status = :undefined
87
+ rescue StepMother::Pending
88
+ @status = :pending
89
+ rescue Exception => exception
90
+ @status = :failed
91
+ @exception = exception
92
+ @exception.backtrace << backtrace_line unless backtrace_line.nil?
93
+ end
94
+ @scenario.step_executed(self) if @scenario
95
+ end
96
+ [self, @status, matched_args]
97
+ end
98
+
99
+ def execute_twin(world, previous, visitor, line, name, *multiline_args)
100
+ # We'll create a new step and execute that
101
+ step = Step.new(line, @keyword, name, *multiline_args)
102
+ step.scenario = @scenario
103
+ step.world = world
104
+ step.previous = previous
105
+ step.__send__(:execute, visitor)
106
+ end
107
+
108
+ ARGUMENT_START = '<'
109
+ ARGUMENT_END = '>'
110
+
111
+ def delimit_argument_names(argument_hash)
112
+ argument_hash.inject({}) { |h,(k,v)| h["#{ARGUMENT_START}#{k}#{ARGUMENT_END}"] = v; h }
113
+ end
114
+
115
+ def replace_name_arguments(argument_hash)
116
+ name_with_arguments_replaced = @name
117
+ argument_hash.each do |name, value|
118
+ name_with_arguments_replaced = name_with_arguments_replaced.gsub(name, value)
119
+ end
120
+ name_with_arguments_replaced
121
+ end
122
+
123
+ def replace_multiline_args_arguments(arguments)
124
+ @multiline_args.map do |arg|
125
+ arg.arguments_replaced(arguments)
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end