aslakhellesoy-cucumber 0.1.99.11 → 0.1.99.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/History.txt +2 -0
  2. data/Manifest.txt +11 -0
  3. data/examples/self_test/features/background/failing_background.feature +10 -0
  4. data/examples/self_test/features/background/failing_background_after_success.feature +11 -0
  5. data/examples/self_test/features/background/multiline_args_background.feature +32 -0
  6. data/examples/self_test/features/background/passing_background.feature +10 -0
  7. data/examples/self_test/features/background/pending_background.feature +10 -0
  8. data/examples/self_test/features/background/scenario_outline_failing_background.feature +16 -0
  9. data/examples/self_test/features/background/scenario_outline_passing_background.feature +16 -0
  10. data/examples/self_test/features/step_definitions/sample_steps.rb +38 -1
  11. data/examples/self_test/features/support/env.rb +1 -0
  12. data/features/background.feature +223 -0
  13. data/features/cucumber_cli.feature +1 -1
  14. data/lib/cucumber/ast.rb +1 -0
  15. data/lib/cucumber/ast/background.rb +88 -0
  16. data/lib/cucumber/ast/feature.rb +9 -3
  17. data/lib/cucumber/ast/scenario.rb +7 -3
  18. data/lib/cucumber/ast/scenario_outline.rb +6 -2
  19. data/lib/cucumber/ast/step.rb +4 -0
  20. data/lib/cucumber/ast/visitor.rb +10 -2
  21. data/lib/cucumber/formatter/pretty.rb +7 -0
  22. data/lib/cucumber/languages.yml +16 -1
  23. data/lib/cucumber/parser/feature.rb +140 -9
  24. data/lib/cucumber/parser/feature.tt +19 -2
  25. data/lib/cucumber/parser/i18n.tt +4 -0
  26. data/lib/cucumber/step_mother.rb +2 -2
  27. data/lib/cucumber/version.rb +1 -1
  28. data/spec/cucumber/ast/background_spec.rb +58 -0
  29. data/spec/cucumber/parser/feature_parser_spec.rb +9 -0
  30. metadata +12 -1
@@ -69,6 +69,8 @@ pure Ruby users have been enjoying for a while.
69
69
  * Pending steps in > steps called from steps (#65 Aslak Hellesøy)
70
70
 
71
71
  === New features
72
+ * Adding support for Background (#153 Joseph Wilk)
73
+ * Added Česky/Czech (Vojtech Salbaba)
72
74
  * New --no-multiline option to reduce noise. Useful if lots of features are failing.
73
75
  * Added ability to pass URIs to cucumber in addition to files and directories. Useful for troubleshooting! (Aslak Hellesøy)
74
76
  * Groups of tabular scenarios (#57 Aslak Hellesøy)
@@ -117,11 +117,19 @@ examples/selenium/Rakefile
117
117
  examples/selenium/features/search.feature
118
118
  examples/selenium/features/step_definitons/stories_steps.rb
119
119
  examples/self_test/README.textile
120
+ examples/self_test/features/background/failing_background.feature
121
+ examples/self_test/features/background/failing_background_after_success.feature
122
+ examples/self_test/features/background/multiline_args_background.feature
123
+ examples/self_test/features/background/passing_background.feature
124
+ examples/self_test/features/background/pending_background.feature
125
+ examples/self_test/features/background/scenario_outline_failing_background.feature
126
+ examples/self_test/features/background/scenario_outline_passing_background.feature
120
127
  examples/self_test/features/call_undefined_step_from_step_def.feature
121
128
  examples/self_test/features/lots_of_undefined.feature
122
129
  examples/self_test/features/outline_sample.feature
123
130
  examples/self_test/features/sample.feature
124
131
  examples/self_test/features/step_definitions/sample_steps.rb
132
+ examples/self_test/features/support/env.rb
125
133
  examples/test_unit/Rakefile
126
134
  examples/test_unit/features/step_definitions/test_unit_steps.rb
127
135
  examples/test_unit/features/test_unit.feature
@@ -139,6 +147,7 @@ examples/watir/Rakefile
139
147
  examples/watir/features/search.feature
140
148
  examples/watir/features/step_definitons/search_steps.rb
141
149
  examples/watir/features/support/env.rb
150
+ features/background.feature
142
151
  features/cucumber_cli.feature
143
152
  features/cucumber_cli_outlines.feature
144
153
  features/report_called_undefined_steps.feature
@@ -161,6 +170,7 @@ lib/autotest/cucumber_rspec.rb
161
170
  lib/autotest/discover.rb
162
171
  lib/cucumber.rb
163
172
  lib/cucumber/ast.rb
173
+ lib/cucumber/ast/background.rb
164
174
  lib/cucumber/ast/comment.rb
165
175
  lib/cucumber/ast/examples.rb
166
176
  lib/cucumber/ast/feature.rb
@@ -218,6 +228,7 @@ rails_generators/feature/USAGE
218
228
  rails_generators/feature/feature_generator.rb
219
229
  rails_generators/feature/templates/feature.erb
220
230
  rails_generators/feature/templates/steps.erb
231
+ spec/cucumber/ast/background_spec.rb
221
232
  spec/cucumber/ast/feature_factory.rb
222
233
  spec/cucumber/ast/feature_spec.rb
223
234
  spec/cucumber/ast/py_string_spec.rb
@@ -0,0 +1,10 @@
1
+ Feature: Failing background sample
2
+
3
+ Background:
4
+ Given failing without a table
5
+
6
+ Scenario: failing background
7
+ Then I should have '10' cukes
8
+
9
+ Scenario: another failing background
10
+ Then I should have '10' cukes
@@ -0,0 +1,11 @@
1
+ Feature: Failing background after previously successful background sample
2
+
3
+ Background:
4
+ Given passing without a table
5
+ And '10' global cukes
6
+
7
+ Scenario: passing background
8
+ Then I should have '10' global cukes
9
+
10
+ Scenario: failing background
11
+ Then I should have '10' global cukes
@@ -0,0 +1,32 @@
1
+ Feature: Passing background with multiline args
2
+
3
+ Background:
4
+ Given table
5
+ |a|b|
6
+ |c|d|
7
+ And multiline string
8
+ """
9
+ I'm a cucumber and I'm okay.
10
+ I sleep all night and I test all day
11
+ """
12
+
13
+ Scenario: passing background
14
+ Then the table should be
15
+ |a|b|
16
+ |c|d|
17
+ Then the multiline string should be
18
+ """
19
+ I'm a cucumber and I'm okay.
20
+ I sleep all night and I test all day
21
+ """
22
+
23
+ Scenario: another passing background
24
+ Then the table should be
25
+ |a|b|
26
+ |c|d|
27
+ Then the multiline string should be
28
+ """
29
+ I'm a cucumber and I'm okay.
30
+ I sleep all night and I test all day
31
+ """
32
+
@@ -0,0 +1,10 @@
1
+ Feature: Passing background sample
2
+
3
+ Background:
4
+ Given '10' cukes
5
+
6
+ Scenario: passing background
7
+ Then I should have '10' cukes
8
+
9
+ Scenario: another passing background
10
+ Then I should have '10' cukes
@@ -0,0 +1,10 @@
1
+ Feature: Pending background sample
2
+
3
+ Background:
4
+ Given pending
5
+
6
+ Scenario: pending background
7
+ Then I should have '10' cukes
8
+
9
+ Scenario: another pending background
10
+ Then I should have '10' cukes
@@ -0,0 +1,16 @@
1
+ Feature: Failing background with scenario outlines sample
2
+
3
+ Background:
4
+ Given failing without a table
5
+
6
+ Scenario Outline: failing background
7
+ Then I should have '<count>' cukes
8
+ Examples:
9
+ |count|
10
+ | 10 |
11
+
12
+ Scenario Outline: another failing background
13
+ Then I should have '<count>' cukes
14
+ Examples:
15
+ |count|
16
+ | 10 |
@@ -0,0 +1,16 @@
1
+ Feature: Passing background with scenario outlines sample
2
+
3
+ Background:
4
+ Given '10' cukes
5
+
6
+ Scenario Outline: passing background
7
+ Then I should have '<count>' cukes
8
+ Examples:
9
+ |count|
10
+ | 10 |
11
+
12
+ Scenario Outline: another passing background
13
+ Then I should have '<count>' cukes
14
+ Examples:
15
+ |count|
16
+ | 10 |
@@ -22,4 +22,41 @@ end
22
22
 
23
23
  Given /^call step "(.*)"$/ do |step|
24
24
  Given step
25
- end
25
+ end
26
+
27
+ Given /^'(.+)' cukes$/ do |cukes|
28
+ @cukes = cukes
29
+ end
30
+
31
+ Then /^I should have '(.+)' cukes$/ do |cukes|
32
+ @cukes.should == cukes
33
+ end
34
+
35
+ Given /^'(.+)' global cukes$/ do |cukes|
36
+ $scenario_runs ||= 0
37
+ flunker if $scenario_runs > 0
38
+ $cukes = cukes
39
+ $scenario_runs += 1
40
+ end
41
+
42
+ Then /^I should have '(.+)' global cukes$/ do |cukes|
43
+ $cukes.should == cukes
44
+ end
45
+
46
+ Given /^table$/ do |table|
47
+ @table = table
48
+ end
49
+
50
+ Given /^multiline string$/ do |string|
51
+ @multiline = string
52
+ end
53
+
54
+ Then /^the table should be$/ do |table|
55
+ @table.to_sexp.should == table.to_sexp
56
+ end
57
+
58
+ Then /^the multiline string should be$/ do |string|
59
+ @multiline.should == string
60
+ end
61
+
62
+
@@ -0,0 +1 @@
1
+ require 'spec/expectations'
@@ -0,0 +1,223 @@
1
+ Feature: backgrounds
2
+ In order to provide a context to my scenarios within a feature
3
+ As a feature editor
4
+ I want to write a background section in my features.
5
+
6
+ Scenario: run a specific scenario with a background
7
+ When I run cucumber -q features/background/passing_background.feature:9 --require features
8
+ Then it should pass with
9
+ """
10
+ Feature: Passing background sample
11
+
12
+ Background:
13
+ Given '10' cukes
14
+
15
+ Scenario: another passing background
16
+ Then I should have '10' cukes
17
+
18
+ 1 scenario
19
+ 2 passed steps
20
+
21
+ """
22
+
23
+ Scenario: run a feature with a background that passes
24
+ When I run cucumber -q features/background/passing_background.feature --require features
25
+ Then it should pass with
26
+ """
27
+ Feature: Passing background sample
28
+
29
+ Background:
30
+ Given '10' cukes
31
+
32
+ Scenario: passing background
33
+ Then I should have '10' cukes
34
+
35
+ Scenario: another passing background
36
+ Then I should have '10' cukes
37
+
38
+ 2 scenarios
39
+ 4 passed steps
40
+
41
+ """
42
+
43
+ Scenario: run a feature with scenario outlines that has a background that passes
44
+ When I run cucumber -q features/background/scenario_outline_passing_background.feature --require features
45
+ Then it should pass with
46
+ """
47
+ Feature: Passing background with scenario outlines sample
48
+
49
+ Background:
50
+ Given '10' cukes
51
+
52
+ Scenario Outline: passing background
53
+ Then I should have '<count>' cukes
54
+
55
+ Examples:
56
+ | count |
57
+ | 10 |
58
+
59
+ Scenario Outline: another passing background
60
+ Then I should have '<count>' cukes
61
+
62
+ Examples:
63
+ | count |
64
+ | 10 |
65
+
66
+ 2 scenarios
67
+ 4 passed steps
68
+
69
+ """
70
+
71
+ Scenario: run a feature with a background that fails
72
+ When I run cucumber -q features/background/failing_background.feature --require features
73
+ Then it should fail with
74
+ """
75
+ Feature: Failing background sample
76
+
77
+ Background:
78
+ Given failing without a table
79
+ FAIL (RuntimeError)
80
+ ./features/step_definitions/sample_steps.rb:2:in `flunker'
81
+ ./features/step_definitions/sample_steps.rb:16:in `/^failing without a table$/'
82
+ features/background/failing_background.feature:4:in `Given failing without a table'
83
+
84
+ Scenario: failing background
85
+ Then I should have '10' cukes
86
+
87
+ Scenario: another failing background
88
+ Then I should have '10' cukes
89
+
90
+ 2 scenarios
91
+ 2 failed steps
92
+ 2 skipped steps
93
+
94
+ """
95
+
96
+ Scenario: run a feature with scenario outlines that has a background that fails
97
+ When I run cucumber -q features/background/scenario_outline_failing_background.feature --require features
98
+ Then it should fail with
99
+ """
100
+ Feature: Failing background with scenario outlines sample
101
+
102
+ Background:
103
+ Given failing without a table
104
+ FAIL (RuntimeError)
105
+ ./features/step_definitions/sample_steps.rb:2:in `flunker'
106
+ ./features/step_definitions/sample_steps.rb:16:in `/^failing without a table$/'
107
+ features/background/scenario_outline_failing_background.feature:4:in `Given failing without a table'
108
+
109
+ Scenario Outline: failing background
110
+ Then I should have '<count>' cukes
111
+
112
+ Examples:
113
+ | count |
114
+ | 10 |
115
+
116
+ Scenario Outline: another failing background
117
+ Then I should have '<count>' cukes
118
+
119
+ Examples:
120
+ | count |
121
+ | 10 |
122
+
123
+ 2 scenarios
124
+ 2 failed steps
125
+ 2 skipped steps
126
+
127
+ """
128
+
129
+ Scenario: run a feature with a background that is pending
130
+ When I run cucumber -q features/background/pending_background.feature --require features
131
+ Then it should pass with
132
+ """
133
+ Feature: Pending background sample
134
+
135
+ Background:
136
+ Given pending
137
+
138
+ Scenario: pending background
139
+ Then I should have '10' cukes
140
+
141
+ Scenario: another pending background
142
+ Then I should have '10' cukes
143
+
144
+ 2 scenarios
145
+ 2 skipped steps
146
+ 2 undefined steps
147
+
148
+ """
149
+
150
+ Scenario: background passes with first scenario but fails with second
151
+ When I run cucumber -q features/background/failing_background_after_success.feature --require features
152
+ Then it should fail with
153
+ """
154
+ Feature: Failing background after previously successful background sample
155
+
156
+ Background:
157
+ Given passing without a table
158
+ And '10' global cukes
159
+
160
+ Scenario: passing background
161
+ Then I should have '10' global cukes
162
+
163
+ Background:
164
+ Given passing without a table
165
+ And '10' global cukes
166
+ FAIL (RuntimeError)
167
+ ./features/step_definitions/sample_steps.rb:2:in `flunker'
168
+ ./features/step_definitions/sample_steps.rb:37:in `/^'(.+)' global cukes$/'
169
+ features/background/failing_background_after_success.feature:3:in `And '10' global cukes'
170
+
171
+ Scenario: failing background
172
+ Then I should have '10' global cukes
173
+
174
+ 2 scenarios
175
+ 1 failed step
176
+ 1 skipped step
177
+ 4 passed steps
178
+
179
+ """
180
+
181
+ Scenario: background with multline args
182
+ When I run cucumber -q features/background/multiline_args_background.feature --require features
183
+ Then it should pass with
184
+ """
185
+ Feature: Passing background with multiline args
186
+
187
+ Background:
188
+ Given table
189
+ | a | b |
190
+ | c | d |
191
+ And multiline string
192
+ \"\"\"
193
+ I'm a cucumber and I'm okay.
194
+ I sleep all night and I test all day
195
+ \"\"\"
196
+
197
+ Scenario: passing background
198
+ Then the table should be
199
+ | a | b |
200
+ | c | d |
201
+ Then the multiline string should be
202
+ \"\"\"
203
+ I'm a cucumber and I'm okay.
204
+ I sleep all night and I test all day
205
+ \"\"\"
206
+
207
+ Scenario: another passing background
208
+ Then the table should be
209
+ | a | b |
210
+ | c | d |
211
+ Then the multiline string should be
212
+ \"\"\"
213
+ I'm a cucumber and I'm okay.
214
+ I sleep all night and I test all day
215
+ \"\"\"
216
+
217
+ 2 scenarios
218
+ 8 passed steps
219
+
220
+ """
221
+
222
+ @josephwilk
223
+ Scenario: run a scenario showing explicit background steps --explicit-background
@@ -148,7 +148,7 @@ Feature: Cucumber command line
148
148
  """
149
149
 
150
150
  Scenario: --dry-run
151
- When I run cucumber --dry-run --no-snippets features
151
+ When I run cucumber --dry-run --no-snippets features/*.feature
152
152
  Then it should pass with
153
153
  """
154
154
  Feature: Calling undefined step
@@ -4,6 +4,7 @@ require 'cucumber/ast/features'
4
4
  require 'cucumber/ast/feature'
5
5
  require 'cucumber/ast/scenario'
6
6
  require 'cucumber/ast/scenario_outline'
7
+ require 'cucumber/ast/background'
7
8
  require 'cucumber/ast/step'
8
9
  require 'cucumber/ast/table'
9
10
  require 'cucumber/ast/py_string'
@@ -0,0 +1,88 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Background < Scenario
4
+
5
+ attr_accessor :world
6
+ attr_reader :status
7
+
8
+ def initialize(comment, line, keyword, steps)
9
+ @record_executed_steps = true
10
+ super(comment, Tags.new(1, []), line, keyword, "", steps)
11
+ end
12
+
13
+ def accept(visitor)
14
+ @world = visitor.new_world
15
+ if already_visited_steps?
16
+ @status = execute_steps(visitor)
17
+ else
18
+ @status = visit_background_and_steps(visitor, @steps)
19
+ @steps_visited = true
20
+ end
21
+ end
22
+
23
+ def step_executed(step)
24
+ @feature.step_executed(step) if @feature && @record_executed_steps
25
+ end
26
+
27
+ def already_visited_steps?
28
+ @steps_visited
29
+ end
30
+
31
+ def to_sexp #:nodoc:
32
+ sexp = [:background, @line, @keyword]
33
+ comment = @comment.to_sexp
34
+ sexp += [comment] if comment
35
+ tags = @tags.to_sexp
36
+ sexp += tags if tags.any?
37
+ steps = @steps.map{|step| step.to_sexp}
38
+ sexp += steps if steps.any?
39
+ sexp
40
+ end
41
+
42
+ private
43
+
44
+ def visit_background_and_steps(visitor, steps)
45
+ visitor.visit_comment(@comment)
46
+ visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
47
+
48
+ previous = :passed
49
+ steps.each do |step|
50
+ step.previous = previous
51
+ step.world = @world
52
+ visitor.visit_step(step)
53
+ previous = step.status
54
+ end
55
+ previous
56
+ end
57
+
58
+ def execute_steps(visitor)
59
+ previous = :passed
60
+ executed_steps = []
61
+ exception = nil
62
+ @steps.each do |step|
63
+ executed_step, previous, _ = step.execute_as_new(@world, previous, visitor, @line)
64
+ executed_steps << executed_step
65
+ exception ||= executed_step.exception
66
+ end
67
+ @steps = executed_steps
68
+
69
+ if exception && @status != :failed
70
+ without_recording_steps do
71
+ @steps_visited = false
72
+ #Since the steps have already been executed they will not be re-run, they will just be displayed
73
+ visitor.visit_background(self)
74
+ end
75
+ end
76
+
77
+ previous
78
+ end
79
+
80
+ def without_recording_steps
81
+ @record_executed_steps = false
82
+ yield
83
+ @record_executed_steps = true
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -5,9 +5,13 @@ module Cucumber
5
5
  attr_accessor :file
6
6
  attr_writer :features, :lines
7
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}
8
+ def initialize(comment, tags, name, feature_elements, background = nil)
9
+ @comment, @tags, @name, @feature_elements, @background = comment, tags, name, feature_elements, background
10
+ feature_elements.each do |feature_element|
11
+ feature_element.feature = self
12
+ feature_element.background = background if background
13
+ end
14
+ background.feature = self if background
11
15
  @lines = []
12
16
  end
13
17
 
@@ -25,6 +29,7 @@ module Cucumber
25
29
  visitor.visit_comment(@comment)
26
30
  visitor.visit_tags(@tags)
27
31
  visitor.visit_feature_name(@name)
32
+
28
33
  @feature_elements.each do |feature_element|
29
34
  visitor.visit_feature_element(feature_element) if @features.visit?(feature_element, @lines)
30
35
  end
@@ -52,6 +57,7 @@ module Cucumber
52
57
  sexp += [comment] if comment
53
58
  tags = @tags.to_sexp
54
59
  sexp += tags if tags.any?
60
+ sexp += [@background.to_sexp] if @background
55
61
  sexp += @feature_elements.map{|e| e.to_sexp}
56
62
  sexp
57
63
  end
@@ -1,7 +1,7 @@
1
1
  module Cucumber
2
2
  module Ast
3
3
  class Scenario
4
- attr_writer :feature
4
+ attr_writer :feature, :background
5
5
 
6
6
  def initialize(comment, tags, line, keyword, name, steps)
7
7
  @comment, @tags, @line, @keyword, @name = comment, tags, line, keyword, name
@@ -22,11 +22,15 @@ module Cucumber
22
22
  end
23
23
 
24
24
  def accept(visitor)
25
+ visitor.visit_background(@background) if @background
25
26
  visitor.visit_comment(@comment)
26
27
  visitor.visit_tags(@tags)
27
28
  visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
28
- visitor.world(self) do |world|
29
- previous = :passed
29
+
30
+ prior_world = @background ? @background.world : nil
31
+ visitor.world(self, prior_world) do |world|
32
+
33
+ previous = @background ? @background.status : :passed
30
34
  @steps.each do |step|
31
35
  step.previous = previous
32
36
  step.world = world
@@ -27,6 +27,7 @@ module Cucumber
27
27
  end
28
28
 
29
29
  def accept(visitor)
30
+ visitor.visit_background(@background) if @background
30
31
  visitor.visit_comment(@comment)
31
32
  visitor.visit_tags(@tags)
32
33
  visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
@@ -40,8 +41,11 @@ module Cucumber
40
41
 
41
42
  def execute_row(cells, visitor, &proc)
42
43
  exception = nil
43
- visitor.world(self) do |world|
44
- previous_status = :passed
44
+
45
+ prior_world = @background ? @background.world : nil
46
+ visitor.world(self, prior_world) do |world|
47
+
48
+ previous_status = @background ? @background.status : :passed
45
49
  argument_hash = cells.to_hash
46
50
  cell_index = 0
47
51
  @steps.each do |step|
@@ -19,6 +19,10 @@ module Cucumber
19
19
 
20
20
  execute_twin(world, previous, visitor, row_line, name, *multiline_args)
21
21
  end
22
+
23
+ def execute_as_new(world, previous, visitor, row_line)
24
+ execute_twin(world, previous, visitor, row_line, @name, *@multiline_args)
25
+ end
22
26
 
23
27
  def accept(visitor)
24
28
  execute(visitor)
@@ -8,8 +8,12 @@ module Cucumber
8
8
  @step_mother = step_mother
9
9
  end
10
10
 
11
- def world(scenario, &proc)
12
- @step_mother.world(scenario, &proc)
11
+ def world(scenario, world = nil, &proc)
12
+ @step_mother.world(scenario, world, &proc)
13
+ end
14
+
15
+ def new_world
16
+ @step_mother.new_world
13
17
  end
14
18
 
15
19
  def step_definition(step_name)
@@ -53,6 +57,10 @@ module Cucumber
53
57
  def visit_feature_element(feature_element)
54
58
  feature_element.accept(self)
55
59
  end
60
+
61
+ def visit_background(background)
62
+ background.accept(self)
63
+ end
56
64
 
57
65
  def visit_examples(examples)
58
66
  examples.accept(self)
@@ -85,6 +85,13 @@ module Cucumber
85
85
  @io.flush
86
86
  end
87
87
 
88
+ def visit_background(background)
89
+ @indent = 2
90
+ background_already_visible = background.already_visited_steps?
91
+ background.accept(self)
92
+ @io.puts unless background_already_visible
93
+ end
94
+
88
95
  def visit_examples(examples)
89
96
  examples.accept(self)
90
97
  end
@@ -45,6 +45,20 @@
45
45
  then: Yna
46
46
  and: A
47
47
  but: Ond
48
+ "cz":
49
+ name: Czech
50
+ native: Česky
51
+ encoding: UTF-8
52
+ feature: Požadavek
53
+ background: Pozadí
54
+ scenario: Scénář
55
+ scenario_outline: Náčrt Scénáře
56
+ examples: Příklady
57
+ given: Pokud
58
+ when: Když
59
+ then: Pak
60
+ and: A
61
+ but: Ale
48
62
  "da":
49
63
  name: Danish
50
64
  native: dansk
@@ -64,6 +78,7 @@
64
78
  native: Deutsch
65
79
  encoding: UTF-8
66
80
  feature: Funktionalität
81
+ background: Grundlage
67
82
  scenario: Szenario
68
83
  scenario_outline: Szenariogrundriss
69
84
  examples: Beispiele
@@ -314,4 +329,4 @@
314
329
  when: 만일
315
330
  then: 그러면
316
331
  and: 그리고
317
- but: 하지만
332
+ but: 하지만
@@ -42,14 +42,22 @@ module Cucumber
42
42
  elements[5]
43
43
  end
44
44
 
45
- def feature_elements
45
+ def background
46
46
  elements[6]
47
47
  end
48
+
49
+ def feature_elements
50
+ elements[7]
51
+ end
48
52
  end
49
53
 
50
54
  module Feature2
51
55
  def build
52
- Ast::Feature.new(comment.build, tags.build, header.text_value, feature_elements.build)
56
+ if background.respond_to?(:build)
57
+ Ast::Feature.new(comment.build, tags.build, header.text_value, feature_elements.build, background.build)
58
+ else
59
+ Ast::Feature.new(comment.build, tags.build, header.text_value, feature_elements.build)
60
+ end
53
61
  end
54
62
  end
55
63
 
@@ -90,8 +98,13 @@ module Cucumber
90
98
  if r11
91
99
  r9 = r11
92
100
  else
93
- self.index = i9
94
- r9 = nil
101
+ r12 = _nt_background
102
+ if r12
103
+ r9 = r12
104
+ else
105
+ self.index = i9
106
+ r9 = nil
107
+ end
95
108
  end
96
109
  end
97
110
  if r9
@@ -103,13 +116,13 @@ module Cucumber
103
116
  s7 << r8
104
117
  if r8
105
118
  if index < input_length
106
- r12 = (SyntaxNode).new(input, index...(index + 1))
119
+ r13 = (SyntaxNode).new(input, index...(index + 1))
107
120
  @index += 1
108
121
  else
109
122
  terminal_parse_failure("any character")
110
- r12 = nil
123
+ r13 = nil
111
124
  end
112
- s7 << r12
125
+ s7 << r13
113
126
  end
114
127
  if s7.last
115
128
  r7 = (SyntaxNode).new(input, i7...index, s7)
@@ -127,8 +140,17 @@ module Cucumber
127
140
  r6 = SyntaxNode.new(input, i6...index, s6)
128
141
  s0 << r6
129
142
  if r6
130
- r13 = _nt_feature_elements
131
- s0 << r13
143
+ r15 = _nt_background
144
+ if r15
145
+ r14 = r15
146
+ else
147
+ r14 = SyntaxNode.new(input, index...index)
148
+ end
149
+ s0 << r14
150
+ if r14
151
+ r16 = _nt_feature_elements
152
+ s0 << r16
153
+ end
132
154
  end
133
155
  end
134
156
  end
@@ -414,6 +436,115 @@ module Cucumber
414
436
  return r0
415
437
  end
416
438
 
439
+ module Background0
440
+ def comment
441
+ elements[0]
442
+ end
443
+
444
+ def white
445
+ elements[1]
446
+ end
447
+
448
+ def background_keyword
449
+ elements[2]
450
+ end
451
+
452
+ def steps
453
+ elements[5]
454
+ end
455
+ end
456
+
457
+ module Background1
458
+ def build
459
+ Ast::Background.new(
460
+ comment.build,
461
+ background_keyword.line,
462
+ background_keyword.text_value,
463
+ steps.build
464
+ )
465
+ end
466
+ end
467
+
468
+ def _nt_background
469
+ start_index = index
470
+ if node_cache[:background].has_key?(index)
471
+ cached = node_cache[:background][index]
472
+ @index = cached.interval.end if cached
473
+ return cached
474
+ end
475
+
476
+ i0, s0 = index, []
477
+ r1 = _nt_comment
478
+ s0 << r1
479
+ if r1
480
+ r2 = _nt_white
481
+ s0 << r2
482
+ if r2
483
+ r3 = _nt_background_keyword
484
+ s0 << r3
485
+ if r3
486
+ s4, i4 = [], index
487
+ loop do
488
+ r5 = _nt_space
489
+ if r5
490
+ s4 << r5
491
+ else
492
+ break
493
+ end
494
+ end
495
+ r4 = SyntaxNode.new(input, i4...index, s4)
496
+ s0 << r4
497
+ if r4
498
+ i6 = index
499
+ s7, i7 = [], index
500
+ loop do
501
+ r8 = _nt_eol
502
+ if r8
503
+ s7 << r8
504
+ else
505
+ break
506
+ end
507
+ end
508
+ if s7.empty?
509
+ self.index = i7
510
+ r7 = nil
511
+ else
512
+ r7 = SyntaxNode.new(input, i7...index, s7)
513
+ end
514
+ if r7
515
+ r6 = r7
516
+ else
517
+ r9 = _nt_eof
518
+ if r9
519
+ r6 = r9
520
+ else
521
+ self.index = i6
522
+ r6 = nil
523
+ end
524
+ end
525
+ s0 << r6
526
+ if r6
527
+ r10 = _nt_steps
528
+ s0 << r10
529
+ end
530
+ end
531
+ end
532
+ end
533
+ end
534
+ if s0.last
535
+ r0 = (SyntaxNode).new(input, i0...index, s0)
536
+ r0.extend(Background0)
537
+ r0.extend(Background1)
538
+ else
539
+ self.index = i0
540
+ r0 = nil
541
+ end
542
+
543
+ node_cache[:background][start_index] = r0
544
+
545
+ return r0
546
+ end
547
+
417
548
  module FeatureElements0
418
549
  def build
419
550
  elements.map{|s| s.build}
@@ -8,9 +8,13 @@ module Cucumber
8
8
  include Table
9
9
 
10
10
  rule feature
11
- white comment white tags white header:(!(scenario_outline / scenario) .)* feature_elements {
11
+ white comment white tags white header:(!(scenario_outline / scenario / background) .)* background:(background)? feature_elements {
12
12
  def build
13
- Ast::Feature.new(comment.build, tags.build, header.text_value, feature_elements.build)
13
+ if background.respond_to?(:build)
14
+ Ast::Feature.new(comment.build, tags.build, header.text_value, feature_elements.build, background.build)
15
+ else
16
+ Ast::Feature.new(comment.build, tags.build, header.text_value, feature_elements.build)
17
+ end
14
18
  end
15
19
  }
16
20
  end
@@ -40,6 +44,19 @@ module Cucumber
40
44
  '#' line_to_eol
41
45
  end
42
46
 
47
+ rule background
48
+ comment white background_keyword space* (eol+ / eof) steps {
49
+ def build
50
+ Ast::Background.new(
51
+ comment.build,
52
+ background_keyword.line,
53
+ background_keyword.text_value,
54
+ steps.build
55
+ )
56
+ end
57
+ }
58
+ end
59
+
43
60
  rule feature_elements
44
61
  (scenario / scenario_outline)* {
45
62
  def build
@@ -2,6 +2,10 @@ module Cucumber
2
2
  module Parser
3
3
  grammar I18n
4
4
 
5
+ rule background_keyword
6
+ "<%= keywords['background'] %>:"
7
+ end
8
+
5
9
  rule scenario_keyword
6
10
  '<%= keywords['scenario'] %>:'
7
11
  end
@@ -62,8 +62,8 @@ module Cucumber
62
62
  step_definition
63
63
  end
64
64
 
65
- def world(scenario, &proc)
66
- world = new_world
65
+ def world(scenario, prior_world = nil, &proc)
66
+ world = prior_world || new_world
67
67
  begin
68
68
  (@before_procs ||= []).each do |proc|
69
69
  world.cucumber_instance_exec(false, 'Before', scenario, &proc)
@@ -3,7 +3,7 @@ module Cucumber #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  TINY = 99
6
- PATCH = 11 # Set to nil for official release
6
+ PATCH = 12 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/ast'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ describe Background do
7
+
8
+ it "should visit a step on the first background run" do
9
+ step = Step.new(7, "Given", "passing")
10
+ background = Background.new(
11
+ comment=Comment.new(""),
12
+ line=99,
13
+ keyword="",
14
+ steps=[
15
+ step
16
+ ])
17
+ visitor = mock('visitor', :null_object => true)
18
+
19
+ visitor.should_receive(:visit_step).with(step)
20
+
21
+ background.accept(visitor)
22
+ end
23
+
24
+ describe "having already visited background once" do
25
+
26
+ before(:each) do
27
+ @mock_step = mock('step', :null_object => true, :text_length => 1)
28
+ @background = Background.new(
29
+ comment=Comment.new(""),
30
+ line=99,
31
+ keyword="",
32
+ steps=[
33
+ @mock_step
34
+ ])
35
+
36
+ @visitor = mock('visitor', :null_object => true)
37
+ @background.accept(@visitor)
38
+ end
39
+
40
+ it "should execute the steps" do
41
+ @mock_step.should_receive(:execute_as_new).and_return(mock('executed step', :null_object => true))
42
+
43
+ @background.accept(@visitor)
44
+ end
45
+
46
+ it "should visit the background if there was a exception when executing a step" do
47
+ mock_executed_step = mock('executed step', :null_object => true, :exception => Exception.new)
48
+ @mock_step.stub!(:execute_as_new).and_return(mock_executed_step)
49
+
50
+ @visitor.should_receive(:visit_background).with(@background)
51
+
52
+ @background.accept(@visitor)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -89,6 +89,15 @@ Feature: hi
89
89
  [:tag, "st3"], [:tag, "st4"]]]
90
90
  end
91
91
  end
92
+
93
+ describe "Background" do
94
+ it "should have steps" do
95
+ parse("Feature: Hi\nBackground:\nGiven I am a step\n").to_sexp.should ==
96
+ [:feature, "Feature: Hi",
97
+ [:background, 2, "Background:",
98
+ [:step, 3, "Given", "I am a step"]]]
99
+ end
100
+ end
92
101
 
93
102
  describe "Scenarios" do
94
103
  it "can be empty" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aslakhellesoy-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.99.11
4
+ version: 0.1.99.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Aslak Helles\xC3\xB8y"
@@ -181,11 +181,19 @@ files:
181
181
  - examples/selenium/features/search.feature
182
182
  - examples/selenium/features/step_definitons/stories_steps.rb
183
183
  - examples/self_test/README.textile
184
+ - examples/self_test/features/background/failing_background.feature
185
+ - examples/self_test/features/background/failing_background_after_success.feature
186
+ - examples/self_test/features/background/multiline_args_background.feature
187
+ - examples/self_test/features/background/passing_background.feature
188
+ - examples/self_test/features/background/pending_background.feature
189
+ - examples/self_test/features/background/scenario_outline_failing_background.feature
190
+ - examples/self_test/features/background/scenario_outline_passing_background.feature
184
191
  - examples/self_test/features/call_undefined_step_from_step_def.feature
185
192
  - examples/self_test/features/lots_of_undefined.feature
186
193
  - examples/self_test/features/outline_sample.feature
187
194
  - examples/self_test/features/sample.feature
188
195
  - examples/self_test/features/step_definitions/sample_steps.rb
196
+ - examples/self_test/features/support/env.rb
189
197
  - examples/test_unit/Rakefile
190
198
  - examples/test_unit/features/step_definitions/test_unit_steps.rb
191
199
  - examples/test_unit/features/test_unit.feature
@@ -203,6 +211,7 @@ files:
203
211
  - examples/watir/features/search.feature
204
212
  - examples/watir/features/step_definitons/search_steps.rb
205
213
  - examples/watir/features/support/env.rb
214
+ - features/background.feature
206
215
  - features/cucumber_cli.feature
207
216
  - features/cucumber_cli_outlines.feature
208
217
  - features/report_called_undefined_steps.feature
@@ -225,6 +234,7 @@ files:
225
234
  - lib/autotest/discover.rb
226
235
  - lib/cucumber.rb
227
236
  - lib/cucumber/ast.rb
237
+ - lib/cucumber/ast/background.rb
228
238
  - lib/cucumber/ast/comment.rb
229
239
  - lib/cucumber/ast/examples.rb
230
240
  - lib/cucumber/ast/feature.rb
@@ -282,6 +292,7 @@ files:
282
292
  - rails_generators/feature/feature_generator.rb
283
293
  - rails_generators/feature/templates/feature.erb
284
294
  - rails_generators/feature/templates/steps.erb
295
+ - spec/cucumber/ast/background_spec.rb
285
296
  - spec/cucumber/ast/feature_factory.rb
286
297
  - spec/cucumber/ast/feature_spec.rb
287
298
  - spec/cucumber/ast/py_string_spec.rb