Class: Cucumber::Ast::Feature

Inherits:
Object
  • Object
show all
Includes:
HasLocation, Names
Defined in:
lib/cucumber/ast/feature.rb

Overview

Represents the root node of a parsed feature.

Instance Attribute Summary collapse

Attributes included from Names

#description, #title

Instance Method Summary collapse

Methods included from HasLocation

#file, #file_colon_line, #line, #location

Methods included from Names

#name

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, tags, keyword, title, description, feature_elements)
  @background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, tags, keyword, title, description, feature_elements
  @background.feature = self
  @location = location
  @feature_elements.each { |e| e.feature = self }
end

Instance Attribute Details

#feature_elementsObject (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

#languageObject

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.visit_tags(@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

Returns:

  • (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_nameObject



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_nameObject



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_namesObject



55
56
57
# File 'lib/cucumber/ast/feature.rb', line 55

def source_tag_names
  source_tags.map { |tag| tag.name }
end

#source_tagsObject



51
52
53
# File 'lib/cucumber/ast/feature.rb', line 51

def source_tags
  @tags.tags
end

#step_countObject



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_sexpObject



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 = @tags.to_sexp
  sexp += tags if tags.any?
  sexp += [@background.to_sexp] if @background
  sexp += @feature_elements.map{|fe| fe.to_sexp}
  sexp
end