Skip to content
Browse files

Make title and description available on feature elements (not just na…

…me - the old school way of doing things)
  • Loading branch information...
1 parent 1c4138b commit 164a72092e2948416079c34d1dd7ee1c55ccaefd @aslakhellesoy aslakhellesoy committed
View
12 lib/cucumber/ast/background.rb
@@ -1,13 +1,15 @@
require 'cucumber/ast/feature_element'
+require 'cucumber/ast/names'
module Cucumber
module Ast
class Background #:nodoc:
include FeatureElement
- attr_reader :feature_elements, :name
+ include Names
+ attr_reader :feature_elements
- def initialize(comment, line, keyword, name, raw_steps)
- @comment, @line, @keyword, @name, @raw_steps = comment, line, keyword, name, raw_steps
+ def initialize(comment, line, keyword, title, description, raw_steps)
+ @comment, @line, @keyword, @title, @description, @raw_steps = comment, line, keyword, title, description, raw_steps
@feature_elements = []
end
@@ -32,7 +34,7 @@ def accept(visitor)
return if Cucumber.wants_to_quit
init
visitor.visit_comment(@comment) unless @comment.empty?
- visitor.visit_background_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
+ visitor.visit_background_name(@keyword, name, file_colon_line(@line), source_indent(first_line_length))
with_visitor(hook_context, visitor) do
visitor.step_mother.before(hook_context)
skip_invoke! if failed?
@@ -79,7 +81,7 @@ def hook_context
def to_sexp
init
sexp = [:background, @line, @keyword]
- sexp += [@name] unless @name.empty?
+ sexp += [name] unless name.empty?
comment = @comment.to_sexp
sexp += [comment] if comment
steps = @steps.to_sexp
View
11 lib/cucumber/ast/examples.rb
@@ -1,10 +1,13 @@
+require 'cucumber/ast/names'
+
module Cucumber
module Ast
class Examples #:nodoc:
+ include Names
attr_writer :outline_table
- def initialize(comment, line, keyword, name, outline_table)
- @comment, @keyword, @name, @outline_table = comment, keyword, name, outline_table
+ def initialize(comment, line, keyword, title, description, outline_table)
+ @comment, @keyword, @title, @description, @outline_table = comment, keyword, title, description, outline_table
end
attr_reader :gherkin_statement
@@ -15,7 +18,7 @@ def gherkin_statement(statement=nil)
def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_comment(@comment) unless @comment.empty?
- visitor.visit_examples_name(@keyword, @name)
+ visitor.visit_examples_name(@keyword, name)
visitor.visit_outline_table(@outline_table)
end
@@ -32,7 +35,7 @@ def failed?
end
def to_sexp
- sexp = [:examples, @keyword, @name]
+ sexp = [:examples, @keyword, name]
comment = @comment.to_sexp
sexp += [comment] if comment
sexp += [@outline_table.to_sexp]
View
13 lib/cucumber/ast/feature.rb
@@ -1,14 +1,17 @@
+require 'cucumber/ast/names'
+
module Cucumber
module Ast
# Represents the root node of a parsed feature.
class Feature #:nodoc:
+ include Names
+
attr_accessor :language
attr_writer :features, :background
attr_reader :file
- attr_reader :name
- def initialize(background, comment, tags, keyword, name, feature_elements)
- @background, @comment, @tags, @keyword, @name, @feature_elements = background, comment, tags, keyword, name.strip, feature_elements
+ def initialize(background, comment, tags, keyword, title, description, feature_elements)
+ @background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, tags, keyword, title, description, feature_elements
end
attr_reader :gherkin_statement
@@ -43,7 +46,7 @@ def accept(visitor)
def indented_name
indent = ""
- @name.split("\n").map do |l|
+ name.split("\n").map do |l|
s = "#{indent}#{l}"
indent = " "
s
@@ -89,7 +92,7 @@ def short_name
def to_sexp
init
- sexp = [:feature, @file, @name]
+ sexp = [:feature, @file, name]
comment = @comment.to_sexp
sexp += [comment] if comment
tags = @tags.to_sexp
View
10 lib/cucumber/ast/feature_element.rb
@@ -6,7 +6,7 @@ module Ast
module FeatureElement #:nodoc:
attr_accessor :feature
- attr_reader :gherkin_statement, :raw_steps
+ attr_reader :gherkin_statement, :raw_steps, :title, :description
def gherkin_statement(statement=nil)
@gherkin_statement ||= statement
end
@@ -32,10 +32,10 @@ def text_length
end
def name_line_lengths
- if @name.strip.empty?
+ if name.strip.empty?
[Ast::Step::INDENT + @keyword.unpack('U*').length + ': '.length]
else
- @name.split("\n").enum_for(:each_with_index).map do |line, line_number|
+ name.split("\n").enum_for(:each_with_index).map do |line, line_number|
if line_number == 0
Ast::Step::INDENT + @keyword.unpack('U*').length + ': '.length + line.unpack('U*').length
else
@@ -46,10 +46,10 @@ def name_line_lengths
end
def matches_scenario_names?(scenario_name_regexps)
- scenario_name_regexps.detect{|name| name =~ @name}
+ scenario_name_regexps.detect{|n| n =~ name}
end
- def backtrace_line(name = "#{@keyword}: #{@name}", line = @line)
+ def backtrace_line(name = "#{@keyword}: #{name}", line = @line)
@feature.backtrace_line(name, line) if @feature
end
View
13 lib/cucumber/ast/names.rb
@@ -0,0 +1,13 @@
+module Cucumber
+ module Ast
+ module Names
+ attr_reader :title, :description
+
+ def name
+ s = @title
+ s += "\n#{@description}" if @description != ""
+ s
+ end
+ end
+ end
+end
View
12 lib/cucumber/ast/scenario.rb
@@ -1,11 +1,13 @@
require 'cucumber/ast/feature_element'
+require 'cucumber/ast/names'
module Cucumber
module Ast
class Scenario #:nodoc:
include FeatureElement
+ include Names
- attr_reader :name, :line
+ attr_reader :line
class EmptyBackground
def failed?
@@ -24,9 +26,9 @@ def init
end
end
- def initialize(background, comment, tags, line, keyword, name, raw_steps)
+ def initialize(background, comment, tags, line, keyword, title, description, raw_steps)
@background = background || EmptyBackground.new
- @comment, @tags, @line, @keyword, @name, @raw_steps = comment, tags, line, keyword, name, raw_steps
+ @comment, @tags, @line, @keyword, @title, @description, @raw_steps = comment, tags, line, keyword, title, description, raw_steps
@exception = @executed = nil
end
@@ -45,7 +47,7 @@ def accept(visitor)
with_visitor(visitor) do
visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_tags(@tags)
- visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
+ visitor.visit_scenario_name(@keyword, name, file_colon_line(@line), source_indent(first_line_length))
skip_invoke! if @background.failed?
visitor.step_mother.with_hooks(self, skip_hooks?) do
@@ -90,7 +92,7 @@ def skip_invoke!
end
def to_sexp
- sexp = [:scenario, @line, @keyword, @name]
+ sexp = [:scenario, @line, @keyword, name]
comment = @comment.to_sexp
sexp += [comment] if comment
tags = @tags.to_sexp
View
27 lib/cucumber/ast/scenario_outline.rb
@@ -1,10 +1,12 @@
+require 'cucumber/ast/feature_element'
+require 'cucumber/ast/names'
+
module Cucumber
module Ast
class ScenarioOutline #:nodoc:
include FeatureElement
+ include Names
- attr_reader :name
-
module ExamplesArray #:nodoc:
def accept(visitor)
return if Cucumber.wants_to_quit
@@ -20,8 +22,8 @@ def accept(visitor)
# * Examples keyword
# * Examples section name
# * Raw matrix
- def initialize(background, comment, tags, line, keyword, name, raw_steps, example_sections)
- @background, @comment, @tags, @line, @keyword, @name, @raw_steps, @example_sections = background, comment, tags, line, keyword, name, raw_steps, example_sections
+ def initialize(background, comment, tags, line, keyword, title, description, raw_steps, example_sections)
+ @background, @comment, @tags, @line, @keyword, @title, @description, @raw_steps, @example_sections = background, comment, tags, line, keyword, title, description, raw_steps, example_sections
end
def add_examples(example_section, gherkin_examples)
@@ -37,14 +39,15 @@ def init
example_section = example_section_and_gherkin_examples[0]
gherkin_examples = example_section_and_gherkin_examples[1]
- examples_comment = example_section[0]
- examples_line = example_section[1]
- examples_keyword = example_section[2]
- examples_name = example_section[3]
- examples_matrix = example_section[4]
+ examples_comment = example_section[0]
+ examples_line = example_section[1]
+ examples_keyword = example_section[2]
+ examples_title = example_section[3]
+ examples_description = example_section[4]
+ examples_matrix = example_section[5]
examples_table = OutlineTable.new(examples_matrix, self)
- ex = Examples.new(examples_comment, examples_line, examples_keyword, examples_name, examples_table)
+ ex = Examples.new(examples_comment, examples_line, examples_keyword, examples_title, examples_description, examples_table)
ex.gherkin_statement(gherkin_examples)
ex
end
@@ -58,7 +61,7 @@ def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_tags(@tags)
- visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
+ visitor.visit_scenario_name(@keyword, name, file_colon_line(@line), source_indent(first_line_length))
visitor.visit_steps(@steps)
skip_invoke! if @background && @background.failed?
@@ -107,7 +110,7 @@ def failed?
def to_sexp
init
- sexp = [:scenario_outline, @keyword, @name]
+ sexp = [:scenario_outline, @keyword, name]
comment = @comment.to_sexp
sexp += [comment] if comment
tags = @tags.to_sexp
View
1 lib/cucumber/ast/table.rb
@@ -74,7 +74,6 @@ def self.parse(text, uri, offset)
def initialize(raw, conversion_procs = NULL_CONVERSIONS.dup)
@cells_class = Cells
@cell_class = Cell
-
raw = ensure_array_of_array(rubify(raw))
# Verify that it's square
transposed = raw.transpose
View
21 lib/cucumber/parser/gherkin_builder.rb
@@ -19,7 +19,8 @@ def feature(feature)
Ast::Comment.new(feature.comments.map{|comment| comment.value}.join("\n")),
Ast::Tags.new(nil, feature.tags.map{|tag| tag.name}),
feature.keyword,
- legacy_name_for(feature.name, feature.description),
+ feature.name.lstrip,
+ feature.description.rstrip,
[]
)
@feature.gherkin_statement(feature)
@@ -31,7 +32,8 @@ def background(background)
Ast::Comment.new(background.comments.map{|comment| comment.value}.join("\n")),
background.line,
background.keyword,
- legacy_name_for(background.name, background.description),
+ background.name,
+ background.description,
steps=[]
)
@feature.background = @background
@@ -47,7 +49,8 @@ def scenario(statement)
Ast::Tags.new(nil, statement.tags.map{|tag| tag.name}),
statement.line,
statement.keyword,
- legacy_name_for(statement.name, statement.description),
+ statement.name,
+ statement.description,
steps=[]
)
@feature.add_feature_element(scenario)
@@ -63,7 +66,8 @@ def scenario_outline(statement)
Ast::Tags.new(nil, statement.tags.map{|tag| tag.name}),
statement.line,
statement.keyword,
- legacy_name_for(statement.name, statement.description),
+ statement.name,
+ statement.description,
steps=[],
example_sections=[]
)
@@ -81,7 +85,8 @@ def examples(examples)
Ast::Comment.new(examples.comments.map{|comment| comment.value}.join("\n")),
examples.line,
examples.keyword,
- legacy_name_for(examples.name, examples.description),
+ examples.name,
+ examples.description,
matrix(examples.rows)
]
@step_container.add_examples(examples_fields, examples)
@@ -109,12 +114,6 @@ def syntax_error(state, event, legal_events, line)
private
- def legacy_name_for(name, description)
- s = name
- s += "\n#{description}" if description != ""
- s
- end
-
def matrix(gherkin_table)
gherkin_table.map do |gherkin_row|
row = gherkin_row.cells
View
15 spec/cucumber/ast/background_spec.rb
@@ -29,7 +29,8 @@ module Ast
comment=Comment.new(''),
line=2,
keyword="",
- name="",
+ title="",
+ description="",
steps=[
Step.new(7, "Given", "y is 5")
])
@@ -40,7 +41,8 @@ module Ast
tags=Tags.new(98,[]),
line=99,
keyword="",
- name="",
+ title="",
+ description="",
steps=[]
)
background.feature = @feature
@@ -55,7 +57,8 @@ module Ast
comment=Comment.new(''),
line=2,
keyword="",
- name="background name",
+ title="background name",
+ description="",
steps=[])
lambda{ background.name }.should_not raise_error
background.name.should == 'background name'
@@ -65,7 +68,8 @@ module Ast
comment=Comment.new(''),
line=2,
keyword="",
- name=nil,
+ title="",
+ description="",
steps=[])
lambda{ background.name }.should_not raise_error
end
@@ -85,7 +89,8 @@ module Ast
comment=Comment.new(''),
line=2,
keyword="",
- name="",
+ title="",
+ description="",
steps=[
Step.new(7, "Given", "y is 5")
])
View
5 spec/cucumber/ast/feature_factory.rb
@@ -26,7 +26,7 @@ def create_feature(dsl)
])
doc_string = Ast::DocString.new(%{\n I like\nCucumber sandwich\n})
- background = Ast::Background.new(Ast::Comment.new(""), 2, "Background:", "",
+ background = Ast::Background.new(Ast::Comment.new(""), 2, "Background:", "", "",
[
Step.new(3, "Given", "a passing step")
]
@@ -38,12 +38,13 @@ def create_feature(dsl)
Ast::Tags.new(6, ['one', 'two']),
"Feature",
"Pretty printing",
+ "",
[Ast::Scenario.new(
background,
Ast::Comment.new(" # My scenario comment \n# On two lines \n"),
Ast::Tags.new(8, ['three', 'four']),
9,
- "Scenario:", "A Scenario",
+ "Scenario:", "A Scenario", "",
[
Step.new(10, "Given", "a passing step with an inline arg:", table),
Step.new(11, "Given", "a happy step with an inline arg:", doc_string),
View
3 spec/cucumber/ast/scenario_outline_spec.rb
@@ -31,7 +31,7 @@ module Ast
Comment.new(""),
Tags.new(18, []),
19,
- "Scenario:", "My outline",
+ "Scenario:", "My outline", "",
[
Step.new(20, 'Given', 'there are <start> cucumbers'),
Step.new(21, 'When', 'I eat <eat> cucumbers'),
@@ -45,6 +45,7 @@ module Ast
24,
'Examples:',
'First table',
+ '',
[
%w{start eat left},
%w{12 5 7},
View
3 spec/cucumber/ast/scenario_spec.rb
@@ -26,7 +26,8 @@ module Ast
tags=Tags.new(98, []),
line=99,
keyword="",
- name="",
+ title="",
+ description="",
steps=[
Step.new(7, "Given", "this is missing"),
Step.new(8, "Given", "y is 5")

0 comments on commit 164a720

Please sign in to comment.
Something went wrong with that request. Please try again.