Class: Cucumber::Ast::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/ast/feature.rb

Overview

Represents the root node of a parsed feature.

Instance Attribute Summary collapse

Instance Method Summary collapse

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, tags, keyword, name, feature_elements)
  @background, @comment, @tags, @keyword, @name, @feature_elements = background, comment, tags, keyword, name.strip, feature_elements
end

Instance Attribute Details

#background=(value) ⇒ Object (writeonly)

Sets the attribute background

Parameters:

  • value

    the value to set the attribute background to.



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

Parameters:

  • value

    the value to set the attribute features to.



6
7
8
# File 'lib/cucumber/ast/feature.rb', line 6

def features=(value)
  @features = value
end

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/cucumber/ast/feature.rb', line 7

def file
  @file
end

#languageObject

:nodoc:



5
6
7
# File 'lib/cucumber/ast/feature.rb', line 5

def language
  @language
end

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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber/ast/feature.rb', line 27

def accept(visitor)
  return if Cucumber.wants_to_quit
  init
  visitor.visit_comment(@comment) unless @comment.empty?
  visitor.visit_tags(@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

Returns:

  • (Boolean)


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

def accept_hook?(hook)
  @tags.accept_hook?(hook)
end

#add_feature_element(feature_element) ⇒ Object



23
24
25
# File 'lib/cucumber/ast/feature.rb', line 23

def add_feature_element(feature_element)
  @feature_elements << feature_element
end

#backtrace_line(step_name, line) ⇒ Object



63
64
65
# File 'lib/cucumber/ast/feature.rb', line 63

def backtrace_line(step_name, line)
  "#{file_colon_line(line)}:in `#{step_name}'"
end

#file_colon_line(line) ⇒ Object



72
73
74
# File 'lib/cucumber/ast/feature.rb', line 72

def file_colon_line(line)
  "#{@file}:#{line}"
end

#indented_nameObject



39
40
41
42
43
44
45
46
# File 'lib/cucumber/ast/feature.rb', line 39

def indented_name
  indent = ""
  @name.split("\n").map do |l|
    s = "#{indent}#{l}"
    indent = "  "
    s
  end.join("\n")
end

#initObject



14
15
16
17
18
19
20
21
# File 'lib/cucumber/ast/feature.rb', line 14

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



56
57
58
59
60
61
# File 'lib/cucumber/ast/feature.rb', line 56

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_nameObject



76
77
78
79
80
81
82
83
# File 'lib/cucumber/ast/feature.rb', line 76

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



48
49
50
# File 'lib/cucumber/ast/feature.rb', line 48

def source_tag_names
  @tags.tag_names
end

#to_sexpObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cucumber/ast/feature.rb', line 85

def to_sexp
  init
  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