Class: Cucumber::Ast::Feature
- Includes:
- HasLocation, Names
- Defined in:
- lib/cucumber/ast/feature.rb
Overview
Represents the root node of a parsed feature.
Instance Attribute Summary collapse
-
#feature_elements ⇒ Object
readonly
Returns the value of attribute feature_elements.
-
#gherkin_statement(statement = nil) ⇒ Object
readonly
Returns the value of attribute gherkin_statement.
-
#language ⇒ Object
Returns the value of attribute language.
Attributes included from Names
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #accept_hook?(hook) ⇒ Boolean
- #backtrace_line(step_name, line) ⇒ Object
- #indented_name ⇒ Object
-
#initialize(location, background, comment, tags, keyword, title, description, feature_elements) ⇒ Feature
constructor
A new instance of Feature.
- #short_name ⇒ Object
- #source_tag_names ⇒ Object
- #source_tags ⇒ Object
- #step_count ⇒ Object
- #to_sexp ⇒ Object
Methods included from HasLocation
#file, #file_colon_line, #line, #location
Methods included from Names
Constructor Details
#initialize(location, background, comment, tags, keyword, title, description, feature_elements) ⇒ Feature
Returns a new instance of Feature.
15 16 17 18 19 20 |
# File 'lib/cucumber/ast/feature.rb', line 15 def initialize(location, background, comment, , keyword, title, description, feature_elements) @background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, , keyword, title, description, feature_elements @background.feature = self @location = location @feature_elements.each { |e| e.feature = self } end |
Instance Attribute Details
#feature_elements ⇒ Object (readonly)
Returns the value of attribute feature_elements.
13 14 15 |
# File 'lib/cucumber/ast/feature.rb', line 13 def feature_elements @feature_elements end |
#gherkin_statement(statement = nil) ⇒ Object (readonly)
Returns the value of attribute gherkin_statement.
22 23 24 |
# File 'lib/cucumber/ast/feature.rb', line 22 def gherkin_statement @gherkin_statement end |
#language ⇒ Object
Returns the value of attribute language.
12 13 14 |
# File 'lib/cucumber/ast/feature.rb', line 12 def language @language end |
Instance Method Details
#accept(visitor) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cucumber/ast/feature.rb', line 31 def accept(visitor) return if Cucumber.wants_to_quit visitor.visit_comment(@comment) unless @comment.empty? visitor.(@tags) visitor.visit_feature_name(@keyword, indented_name) visitor.visit_background(@background) if !@background.is_a?(EmptyBackground) @feature_elements.each do |feature_element| visitor.visit_feature_element(feature_element) end end |
#accept_hook?(hook) ⇒ Boolean
59 60 61 |
# File 'lib/cucumber/ast/feature.rb', line 59 def accept_hook?(hook) @tags.accept_hook?(hook) end |
#backtrace_line(step_name, line) ⇒ Object
63 64 65 |
# File 'lib/cucumber/ast/feature.rb', line 63 def backtrace_line(step_name, line) "#{location.on_line(line)}:in `#{step_name}'" end |
#indented_name ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/cucumber/ast/feature.rb', line 42 def indented_name indent = "" name.split("\n").map do |l| s = "#{indent}#{l}" indent = " " s end.join("\n") end |
#short_name ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/cucumber/ast/feature.rb', line 67 def short_name first_line = name.split(/\n/)[0] if first_line =~ /#{language.keywords('feature')}:(.*)/ $1.strip else first_line end end |
#source_tag_names ⇒ Object
55 56 57 |
# File 'lib/cucumber/ast/feature.rb', line 55 def source_tag_names .map { |tag| tag.name } end |
#source_tags ⇒ Object
51 52 53 |
# File 'lib/cucumber/ast/feature.rb', line 51 def @tags. end |
#step_count ⇒ Object
27 28 29 |
# File 'lib/cucumber/ast/feature.rb', line 27 def step_count units.inject(0) { |total, unit| total += unit.step_count } end |
#to_sexp ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cucumber/ast/feature.rb', line 76 def to_sexp sexp = [:feature, file, name] comment = @comment.to_sexp sexp += [comment] if comment = @tags.to_sexp sexp += if .any? sexp += [@background.to_sexp] if @background sexp += @feature_elements.map{|fe| fe.to_sexp} sexp end |