Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Parse descriptions correctly

  • Loading branch information...
commit f8d200bf39d883817501320db7eb9cd2177169d8 1 parent 9bf3924
Josep M. Bach txus authored
9 lib/gherkin/parser.rb
View
@@ -14,12 +14,15 @@ def indent(num=2)
rule(:feature_line) { str('Feature:') >> space? >> text.as(:name) }
rule(:scenario_line) { indent(2) >> str('Scenario:') >> space? >> text.as(:name) }
- rule(:background_line) { indent(2) >> str('Background:') }
rule(:step_keyword) { str('Given') | str('When') | str('Then') | str('And') | str('But') }
rule(:comment) { str('#') >> text.as(:comment) }
- rule(:description) { indent(2) >> text.as(:description) }
+
+ rule(:description_text) { (str('Background:') | str('Scenario:') | str('@')).absent? >> text }
+ rule(:description) { (indent(2) >> description_text >> newline).repeat }
+
+ rule(:background_line) { indent(2) >> str('Background:') }
rule(:step) { indent(4) >> step_keyword.as(:keyword) >> space? >> text.as(:name) }
rule(:steps) { (step.as(:step) >> newline.maybe).repeat }
@@ -31,7 +34,7 @@ def indent(num=2)
rule(:background) { background_line >> newline >> steps.as(:steps) }
- rule(:feature) { feature_line >> newline >> background.as(:background).maybe >> scenarios.as(:scenarios) }
+ rule(:feature) { feature_line >> newline >> description >> background.as(:background).maybe >> scenarios.as(:scenarios) }
rule(:main) { feature.as(:feature) }
11 test/gherkin/parser_test.rb
View
@@ -57,10 +57,13 @@ module Gherkin
end
describe 'Description parsing' do
- it 'parses descriptions ignoring their content' do
- p(:description, " In order to know what the heck is Gherkin").size.must_be :>, 0
- p(:description, " As a developer").size.must_be :>, 0
- p(:description, " I want it to behave in an expected way").size.must_be :>, 0
+ it 'parses multiline descriptions' do
+ description = """ In order to know what the heck is Gherkin
+ As a developer
+ I want it to behave in an expected way
+"""
+ parser = Gherkin::Parser.new
+ parser.description.parse(description)
end
end
21 test/gherkin/transform_test.rb
View
@@ -5,6 +5,9 @@ module Gherkin
describe 'Feature parsing' do
before do
@scenario = """Feature: My Feature
+ In order to do something
+ As a developer
+ I want to be happy
Background:
Given something happens before anything else happens
@@ -32,29 +35,29 @@ module Gherkin
background = @result.background
background.must_be_kind_of AST::Background
- background.line.must_equal 3
+ background.line.must_equal 6
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.first.line.must_equal 7
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
+ background.steps.last.line.must_equal 8
first_scenario = @result.scenarios.first
first_scenario.must_be_kind_of AST::Scenario
- first_scenario.line.must_equal 7
+ first_scenario.line.must_equal 10
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.first.line.must_equal 11
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
+ first_scenario.steps.last.line.must_equal 12
last_scenario = @result.scenarios.last
last_scenario.must_be_kind_of AST::Scenario
- last_scenario.line.must_equal 12
+ last_scenario.line.must_equal 15
last_scenario.name.must_equal 'something else happens'
last_scenario.tags.first.name.must_equal 'javascript'
@@ -62,10 +65,10 @@ module Gherkin
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.first.line.must_equal 16
last_scenario.steps.last.keyword.must_equal 'Then'
last_scenario.steps.last.name.must_equal 'bar'
- last_scenario.steps.last.line.must_equal 14
+ last_scenario.steps.last.line.must_equal 17
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.