Skip to content

Commit cd7d3ae

Browse files
Add examples of tests using the Rule keyword
Note: the writer tests is currently disabled, not sure this is really needed.
1 parent 6d8c10c commit cd7d3ae

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

lib/cucumber/core/gherkin/writer.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Feature
4848

4949
default_keyword 'Feature'
5050

51-
elements :background, :scenario, :scenario_outline
51+
elements :background, :rule, :scenario, :scenario_outline
5252

5353
def build(source = [])
5454
elements.inject(source + statements) { |acc, el| el.build(acc) + [NEW_LINE] }
@@ -89,6 +89,24 @@ def statements
8989
end
9090
end
9191

92+
class Rule
93+
include HasElements
94+
include HasOptionsInitializer
95+
include HasDescription
96+
include Indentation.level 2
97+
98+
default_keyword 'Rule'
99+
100+
elements :scenario
101+
102+
private
103+
def statements
104+
prepare_statements comments_statement,
105+
name_statement,
106+
description_statement
107+
end
108+
end
109+
92110
class Scenario
93111
include HasElements
94112
include HasOptionsInitializer

spec/cucumber/core/gherkin/parser_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,44 @@ def self.source(&block)
8989
end
9090
end
9191

92+
context "when scenario is inside a rule" do
93+
source do
94+
feature do
95+
rule do
96+
scenario do
97+
step 'text'
98+
end
99+
end
100+
end
101+
end
102+
103+
it "passes on the pickle" do
104+
expect( receiver ).to receive(:pickle)
105+
parse
106+
end
107+
end
108+
109+
context "when there are multiple rules and scenarios" do
110+
source do
111+
feature do
112+
rule do
113+
scenario do
114+
step 'text'
115+
end
116+
end
117+
rule do
118+
scenario do
119+
step 'text'
120+
end
121+
end
122+
end
123+
end
124+
125+
it "passes on the pickles" do
126+
expect( receiver ).to receive(:pickle).twice
127+
parse
128+
end
129+
end
92130
end
93131
end
94132
end

spec/cucumber/core/gherkin/writer_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ module Cucumber::Core::Gherkin
233233
end
234234
end
235235
end
236+
237+
context 'with rules' do
238+
xit 'can have a description' do
239+
source = gherkin do
240+
feature do
241+
rule name: "Simple", description: "My castle, my rule" do
242+
scenario name: "My scenario"
243+
end
244+
end
245+
end
246+
247+
expect( source.body ).to eq <<-END.unindent
248+
Feature:
249+
250+
Rule: Simple
251+
My castle, my rules
252+
253+
Scenario: My scenario
254+
END
255+
end
256+
end
236257
end
237258

238259
it 'generates a complex feature' do

0 commit comments

Comments
 (0)