Permalink
Browse files

Store feature description

In order for better formatters in Spinach to work
we need to store metadata like the feature description
so spinach formatters can retreive it and output it
  • Loading branch information...
1 parent 0f5c072 commit 722eacaff4a019b5349198d5c125c7b00b5edc1c @iain iain committed May 31, 2012
Showing with 23 additions and 8 deletions.
  1. +1 −0 lib/gherkin/ast.rb
  2. +3 −3 lib/gherkin/parser/gherkin.y
  3. +15 −5 lib/gherkin/parser/parser.rb
  4. +4 −0 test/gherkin/parser_test.rb
View
@@ -16,6 +16,7 @@ def pos(filename, line=nil)
class Feature < Node
attr_reader :name, :background, :scenarios, :tags
attr_writer :background, :scenarios, :tags
+ attr_accessor :description
include Enumerable
@@ -40,7 +40,7 @@ rule
FeatureName { result = val[0] }
| FeatureName Newline { result = val[0] }
| FeatureName Newline
- Description { result = val[0] }
+ Description { result = val[0]; result.description = val[2] }
;
FeatureName:
@@ -49,8 +49,8 @@ rule
;
Description:
- TEXT Newline
- | Description TEXT Newline
+ TEXT Newline { result = val[0] }
+ | Description TEXT Newline { result = val[0...-1].flatten }
;
Background:
@@ -96,8 +96,8 @@ def parse(input)
3, 20, :_reduce_13,
2, 22, :_reduce_14,
3, 22, :_reduce_15,
- 2, 23, :_reduce_none,
- 3, 23, :_reduce_none,
+ 2, 23, :_reduce_16,
+ 3, 23, :_reduce_17,
2, 21, :_reduce_18,
2, 24, :_reduce_19,
1, 25, :_reduce_20,
@@ -268,7 +268,7 @@ def _reduce_12(val, _values, result)
module_eval(<<'.,.,', 'gherkin.y', 42)
def _reduce_13(val, _values, result)
- result = val[0]
+ result = val[0]; result.description = val[2]
result
end
.,.,
@@ -287,9 +287,19 @@ def _reduce_15(val, _values, result)
end
.,.,
-# reduce 16 omitted
+module_eval(<<'.,.,', 'gherkin.y', 51)
+ def _reduce_16(val, _values, result)
+ result = val[0]
+ result
+ end
+.,.,
-# reduce 17 omitted
+module_eval(<<'.,.,', 'gherkin.y', 52)
+ def _reduce_17(val, _values, result)
+ result = val[0...-1].flatten
+ result
+ end
+.,.,
module_eval(<<'.,.,', 'gherkin.y', 57)
def _reduce_18(val, _values, result)
@@ -32,6 +32,10 @@ module Gherkin
it 'generates a nice tree' do
@result.must_be_kind_of AST::Feature
@result.line.must_equal 1
+ @result.description.must_equal [
+ "In order to do something",
+ "As a developer",
+ "I want to be happy"]
background = @result.background
background.must_be_kind_of AST::Background

0 comments on commit 722eaca

Please sign in to comment.