Class: Cucumber::Ast::Feature
Overview
Represents the root node of a parsed feature.
Instance Attribute Summary collapse
-
#features ⇒ Object
writeonly
Sets the attribute features.
-
#file ⇒ Object
Returns the value of attribute file.
-
#language ⇒ Object
Returns the value of attribute language.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #accept_hook?(hook) ⇒ Boolean
- #backtrace_line(step_name, line) ⇒ Object
- #feature_and_children_tag_count(tag) ⇒ Object
- #file_colon_line(line) ⇒ Object
-
#initialize(background, comment, tags, name, feature_elements) ⇒ Feature
constructor
A new instance of Feature.
- #next_feature_element(feature_element, &proc) ⇒ Object
- #short_name ⇒ Object
- #tag_count(tag) ⇒ Object
- #to_sexp ⇒ Object
Constructor Details
#initialize(background, comment, tags, name, feature_elements) ⇒ Feature
Returns a new instance of Feature.
9 10 11 12 13 14 15 16 |
# File 'lib/cucumber/ast/feature.rb', line 9 def initialize(background, comment, , name, feature_elements) @background, @comment, @tags, @name, @feature_elements = background, comment, , name.strip, feature_elements background.feature = self if background @feature_elements.each do |feature_element| feature_element.feature = self end end |
Instance Attribute Details
#features=(value) ⇒ Object (writeonly)
Sets the attribute features
6 7 8 |
# File 'lib/cucumber/ast/feature.rb', line 6 def features=(value) @features = value end |
#file ⇒ Object
Returns the value of attribute file.
5 6 7 |
# File 'lib/cucumber/ast/feature.rb', line 5 def file @file end |
#language ⇒ Object
Returns the value of attribute language.
5 6 7 |
# File 'lib/cucumber/ast/feature.rb', line 5 def language @language end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cucumber/ast/feature.rb', line 7 def name @name end |
Instance Method Details
#accept(visitor) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cucumber/ast/feature.rb', line 18 def accept(visitor) return if $cucumber_interrupted visitor.visit_comment(@comment) unless @comment.empty? visitor.(@tags) visitor.visit_feature_name(@name) visitor.visit_background(@background) if @background @feature_elements.each do |feature_element| visitor.visit_feature_element(feature_element) end end |
#accept_hook?(hook) ⇒ Boolean
29 30 31 |
# File 'lib/cucumber/ast/feature.rb', line 29 def accept_hook?(hook) @tags.accept_hook?(hook) end |
#backtrace_line(step_name, line) ⇒ Object
39 40 41 |
# File 'lib/cucumber/ast/feature.rb', line 39 def backtrace_line(step_name, line) "#{file_colon_line(line)}:in `#{step_name}'" end |
#feature_and_children_tag_count(tag) ⇒ Object
55 56 57 58 |
# File 'lib/cucumber/ast/feature.rb', line 55 def feature_and_children_tag_count(tag) children_tag_count = @feature_elements.inject(0){|count, feature_element| count += feature_element.tag_count(tag)} children_tag_count + tag_count(tag) end |
#file_colon_line(line) ⇒ Object
43 44 45 |
# File 'lib/cucumber/ast/feature.rb', line 43 def file_colon_line(line) "#{@file}:#{line}" end |
#next_feature_element(feature_element, &proc) ⇒ Object
33 34 35 36 37 |
# File 'lib/cucumber/ast/feature.rb', line 33 def next_feature_element(feature_element, &proc) index = @feature_elements.index(feature_element) next_one = @feature_elements[index+1] proc.call(next_one) if next_one end |
#short_name ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/cucumber/ast/feature.rb', line 60 def short_name first_line = name.split(/\n/)[0] if first_line =~ /#{language.keywords('feature', true)}:(.*)/ $1.strip else first_line end end |
#tag_count(tag) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/cucumber/ast/feature.rb', line 47 def tag_count(tag) if @tags.respond_to?(:count) @tags.count(tag) # 1.9 else @tags.select{|t| t == tag}.length # 1.8 end end |
#to_sexp ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cucumber/ast/feature.rb', line 69 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 |