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, name, feature_elements) ⇒ Feature

Returns a new instance of Feature.



8
9
10
11
12
13
14
15
# File 'lib/cucumber/ast/feature.rb', line 8

def initialize(background, comment, tags, name, feature_elements)
  @background, @comment, @tags, @name, @feature_elements = background, comment, tags, name, feature_elements
  @lines = []

  @feature_elements.each do |feature_element|
    feature_element.feature = self
  end
end

Instance Attribute Details

#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.



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

def file
  @file
end

#lines=(value) ⇒ Object (writeonly)

Sets the attribute lines

Parameters:

  • value

    the value to set the attribute lines to.



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

def lines=(value)
  @lines = value
end

Instance Method Details

#accept(visitor) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/cucumber/ast/feature.rb', line 17

def accept(visitor)
  visitor.current_feature_lines = @lines
  visitor.visit_comment(@comment)
  visitor.visit_tags(@tags)
  visitor.visit_feature_name(@name)
  visitor.visit_background(@background) if @background
  @feature_elements.each do |feature_element|
    visitor.visit_feature_element(feature_element) if feature_element.descend?(visitor)
  end
end

#backtrace_line(step_name, line) ⇒ Object



42
43
44
# File 'lib/cucumber/ast/feature.rb', line 42

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

#descend?(visitor) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cucumber/ast/feature.rb', line 28

def descend?(visitor)
  @feature_elements.detect{ |feature_element| feature_element.descend?(visitor) }
end

#file_colon_line(line) ⇒ Object



46
47
48
# File 'lib/cucumber/ast/feature.rb', line 46

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

#has_tags?(tags) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cucumber/ast/feature.rb', line 32

def has_tags?(tags)
  @tags.has_tags?(tags)
end

#next_feature_element(feature_element, &proc) ⇒ Object



36
37
38
39
40
# File 'lib/cucumber/ast/feature.rb', line 36

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

#to_sexpObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/cucumber/ast/feature.rb', line 50

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