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(comment, tags, name, feature_elements, background = nil) ⇒ Feature

Returns a new instance of Feature.



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

def initialize(comment, tags, name, feature_elements, background = nil)
  @comment, @tags, @name, @feature_elements, @background = comment, tags, name, feature_elements, background
  feature_elements.each do |feature_element| 
    feature_element.feature = self
    feature_element.background = background if background
  end
  background.feature = self if background
  @lines = []
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



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

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

#backtrace_line(step_name, line) ⇒ Object



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

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

#file_line(line) ⇒ Object



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

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

#matches_scenario_names?(scenario_names) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches_scenario_names?(scenario_names)
  @feature_elements.detect{|e| e.matches_scenario_names?(scenario_names)}
end

#scenario_executed(scenario) ⇒ Object



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

def scenario_executed(scenario)
  @features.scenario_executed(scenario) if @features
end

#step_executed(step) ⇒ Object



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

def step_executed(step)
  @features.step_executed(step) if @features
end

#tagged_with?(tag_names, check_elements = true) ⇒ Boolean

Returns:

  • (Boolean)


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

def tagged_with?(tag_names, check_elements=true)
  @tags.among?(tag_names) || 
  (check_elements && @feature_elements.detect{|e| e.tagged_with?(tag_names)})
end

#to_sexpObject



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

def to_sexp
  sexp = [:feature, @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{|e| e.to_sexp}
  sexp
end