Class: Cucumber::Ast::Feature
Overview
Represents the root node of a parsed feature.
Instance Attribute Summary collapse
-
#background ⇒ Object
writeonly
Sets the attribute background.
-
#features ⇒ Object
writeonly
Sets the attribute features.
-
#file ⇒ Object
Returns the value of attribute file.
-
#gherkin_statement(statement = nil) ⇒ Object
readonly
Returns the value of attribute gherkin_statement.
-
#language ⇒ Object
:nodoc:.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #accept_hook?(hook) ⇒ Boolean
- #add_feature_element(feature_element) ⇒ Object
- #backtrace_line(step_name, line) ⇒ Object
- #file_colon_line(line) ⇒ Object
- #indented_name ⇒ Object
- #init ⇒ Object
-
#initialize(background, comment, tags, keyword, name, feature_elements) ⇒ Feature
constructor
A new instance of Feature.
- #next_feature_element(feature_element, &proc) ⇒ Object
- #short_name ⇒ Object
- #source_tag_names ⇒ Object
- #to_sexp ⇒ Object
Constructor Details
#initialize(background, comment, tags, keyword, name, feature_elements) ⇒ Feature
Returns a new instance of Feature.
10 11 12 |
# File 'lib/cucumber/ast/feature.rb', line 10 def initialize(background, comment, , keyword, name, feature_elements) @background, @comment, @tags, @keyword, @name, @feature_elements = background, comment, , keyword, name.strip, feature_elements end |
Instance Attribute Details
#background=(value) ⇒ Object (writeonly)
Sets the attribute background
6 7 8 |
# File 'lib/cucumber/ast/feature.rb', line 6 def background=(value) @background = value end |
#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.
7 8 9 |
# File 'lib/cucumber/ast/feature.rb', line 7 def file @file end |
#gherkin_statement(statement = nil) ⇒ Object (readonly)
Returns the value of attribute gherkin_statement.
14 15 16 |
# File 'lib/cucumber/ast/feature.rb', line 14 def gherkin_statement @gherkin_statement end |
#language ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/cucumber/ast/feature.rb', line 5 def language @language end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/cucumber/ast/feature.rb', line 8 def name @name end |
Instance Method Details
#accept(visitor) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cucumber/ast/feature.rb', line 32 def accept(visitor) return if Cucumber.wants_to_quit init visitor.visit_comment(@comment) unless @comment.empty? visitor.(@tags) visitor.visit_feature_name(@keyword, indented_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
57 58 59 |
# File 'lib/cucumber/ast/feature.rb', line 57 def accept_hook?(hook) @tags.accept_hook?(hook) end |
#add_feature_element(feature_element) ⇒ Object
28 29 30 |
# File 'lib/cucumber/ast/feature.rb', line 28 def add_feature_element(feature_element) @feature_elements << feature_element end |
#backtrace_line(step_name, line) ⇒ Object
68 69 70 |
# File 'lib/cucumber/ast/feature.rb', line 68 def backtrace_line(step_name, line) "#{file_colon_line(line)}:in `#{step_name}'" end |
#file_colon_line(line) ⇒ Object
77 78 79 |
# File 'lib/cucumber/ast/feature.rb', line 77 def file_colon_line(line) "#{@file}:#{line}" end |
#indented_name ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/cucumber/ast/feature.rb', line 44 def indented_name indent = "" @name.split("\n").map do |l| s = "#{indent}#{l}" indent = " " s end.join("\n") end |
#init ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/cucumber/ast/feature.rb', line 19 def init @background.feature = self if @background @background.init if @background @feature_elements.each do |feature_element| feature_element.init feature_element.feature = self end end |
#next_feature_element(feature_element, &proc) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/cucumber/ast/feature.rb', line 61 def next_feature_element(feature_element, &proc) init index = @feature_elements.index(feature_element) next_one = @feature_elements[index+1] proc.call(next_one) if next_one end |
#short_name ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/cucumber/ast/feature.rb', line 81 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
53 54 55 |
# File 'lib/cucumber/ast/feature.rb', line 53 def source_tag_names @tags.tag_names end |
#to_sexp ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cucumber/ast/feature.rb', line 90 def to_sexp init 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 |