Permalink
Browse files

Steps now get keywords

  • Loading branch information...
Josep M. Bach
Josep M. Bach committed Nov 11, 2011
1 parent 83e9313 commit 7e768fa00e0883925bf9622353b041da2901bb9f
View
@@ -65,11 +65,12 @@ def each
end
class Step < Node
- attr_reader :name
- def initialize(name)
+ attr_reader :name, :keyword
+ def initialize(name, keyword)
@line, @column = name.line_and_column
- @name = name.to_s
+ @name = name.to_s
+ @keyword = keyword.to_s
end
end
View
@@ -21,7 +21,7 @@ def indent(num=2)
rule(:comment) { str('#') >> text.as(:comment) }
rule(:description) { indent(2) >> text.as(:description) }
- rule(:step) { indent(4) >> step_keyword >> space? >> text.as(:name) }
+ rule(:step) { indent(4) >> step_keyword.as(:keyword) >> space? >> text.as(:name) }
rule(:steps) { (step.as(:step) >> newline.maybe).repeat }
rule(:tags) { indent(2) >> (str('@') >> identifier.as(:tag) >> str(' ').maybe).repeat(1) }
View
@@ -39,8 +39,9 @@ class Transform < Parslet::Transform
rule(
step: {
name: simple(:name),
+ keyword: simple(:keyword),
}
- ) { AST::Step.new(name) }
+ ) { AST::Step.new(name, keyword) }
rule(
tag: simple(:name)
View
@@ -26,7 +26,7 @@ module AST
end
end
- [Feature, Scenario, Step, Tag].each do |node|
+ [Feature, Scenario, Tag].each do |node|
describe node do
it 'is a Node' do
node.ancestors.must_include Node
@@ -114,5 +114,22 @@ def name.to_s; 'Name'; end
end
end
end
+
+ describe Step do
+ it 'is a Node' do
+ Step.ancestors.must_include Node
+ end
+
+ it 'has a line and column' do
+ name = OpenStruct.new(line_and_column: [2, 13])
+ def name.to_s; 'Name'; end
+
+ instance = Step.new(name, 'Given')
+ instance.name.must_equal 'Name'
+ instance.keyword.must_equal 'Given'
+ instance.line.must_equal 2
+ instance.column.must_equal 13
+ end
+ end
end
end
@@ -19,23 +19,33 @@ module Gherkin
describe 'Steps' do
it 'parses a Given step' do
- p(:step, " Given I have an empty array", :name).must_equal "I have an empty array"
+ step = " Given I have an empty array"
+ p(:step, step, :name).must_equal "I have an empty array"
+ p(:step, step, :keyword).must_equal "Given"
end
it 'parses a When step' do
- p(:step, " When I have an empty array", :name).must_equal "I have an empty array"
+ step = " When I have an empty array"
+ p(:step, step, :name).must_equal "I have an empty array"
+ p(:step, step, :keyword).must_equal "When"
end
it 'parses a Then step' do
- p(:step, " Then I have an empty array", :name).must_equal "I have an empty array"
+ step = " Then I have an empty array"
+ p(:step, step, :name).must_equal "I have an empty array"
+ p(:step, step, :keyword).must_equal "Then"
end
it 'parses an And step' do
- p(:step, " And I have an empty array", :name).must_equal "I have an empty array"
+ step = " And I have an empty array"
+ p(:step, step, :name).must_equal "I have an empty array"
+ p(:step, step, :keyword).must_equal "And"
end
it 'parses a But step' do
- p(:step, " But I have an empty array", :name).must_equal "I have an empty array"
+ step = " But I have an empty array"
+ p(:step, step, :name).must_equal "I have an empty array"
+ p(:step, step, :keyword).must_equal "But"
end
end
end
@@ -34,17 +34,21 @@ module Gherkin
background.must_be_kind_of AST::Background
background.line.must_equal 3
background.column.must_equal 3
+ background.steps.first.keyword.must_equal 'Given'
background.steps.first.name.must_equal 'something happens before anything else happens'
background.steps.first.line.must_equal 4
+ background.steps.last.keyword.must_equal 'And'
background.steps.last.name.must_equal 'more things happens before anything else happens'
background.steps.last.line.must_equal 5
first_scenario = @result.scenarios.first
first_scenario.must_be_kind_of AST::Scenario
first_scenario.line.must_equal 7
first_scenario.name.must_equal 'something happens'
+ first_scenario.steps.first.keyword.must_equal 'Given'
first_scenario.steps.first.name.must_equal 'something happens'
first_scenario.steps.first.line.must_equal 8
+ first_scenario.steps.last.keyword.must_equal 'Then'
first_scenario.steps.last.name.must_equal 'something cooler happens'
first_scenario.steps.last.line.must_equal 9
@@ -56,8 +60,10 @@ module Gherkin
last_scenario.tags.first.name.must_equal 'javascript'
last_scenario.tags.last.name.must_equal 'wip'
+ last_scenario.steps.first.keyword.must_equal 'Given'
last_scenario.steps.first.name.must_equal 'foo'
last_scenario.steps.first.line.must_equal 13
+ last_scenario.steps.last.keyword.must_equal 'Then'
last_scenario.steps.last.name.must_equal 'bar'
last_scenario.steps.last.line.must_equal 14
end

0 comments on commit 7e768fa

Please sign in to comment.