Module: Cucumber::Ast::FeatureElement

Included in:
Background, Scenario, ScenarioOutline
Defined in:
lib/cucumber/ast/feature_element.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#featureObject

Returns the value of attribute feature.



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

def feature
  @feature
end

#gherkin_statement(statement = nil) ⇒ Object (readonly)

Returns the value of attribute gherkin_statement.



9
10
11
# File 'lib/cucumber/ast/feature_element.rb', line 9

def gherkin_statement
  @gherkin_statement
end

#raw_stepsObject (readonly)

Returns the value of attribute raw_steps.



9
10
11
# File 'lib/cucumber/ast/feature_element.rb', line 9

def raw_steps
  @raw_steps
end

Instance Method Details

#accept_hook?(hook) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/cucumber/ast/feature_element.rb', line 65

def accept_hook?(hook)
  Gherkin::TagExpression.new(hook.tag_expressions).eval(source_tag_names)
end

#add_step(step) ⇒ Object



14
15
16
# File 'lib/cucumber/ast/feature_element.rb', line 14

def add_step(step)
  @raw_steps << step
end

#attach_steps(steps) ⇒ Object



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

def attach_steps(steps)
  steps.each {|step| step.feature_element = self}
end

#backtrace_line(name = "#{@keyword}: #{@name}", line = @line) ⇒ Object



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

def backtrace_line(name = "#{@keyword}: #{@name}", line = @line)
  @feature.backtrace_line(name, line) if @feature
end

#file_colon_line(line = @line) ⇒ Object



22
23
24
# File 'lib/cucumber/ast/feature_element.rb', line 22

def file_colon_line(line = @line)
  @feature.file_colon_line(line) if @feature
end

#first_line_lengthObject



26
27
28
# File 'lib/cucumber/ast/feature_element.rb', line 26

def first_line_length
  name_line_lengths[0]
end

#languageObject



73
74
75
# File 'lib/cucumber/ast/feature_element.rb', line 73

def language
  @feature.language if @feature
end

#matches_scenario_names?(scenario_name_regexps) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches_scenario_names?(scenario_name_regexps)
  scenario_name_regexps.detect{|name| name =~ @name}
end

#max_line_lengthObject



60
61
62
63
# File 'lib/cucumber/ast/feature_element.rb', line 60

def max_line_length
  init
  @steps.max_line_length(self)
end

#name_line_lengthsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber/ast/feature_element.rb', line 34

def name_line_lengths
  if @name.strip.empty?
    [Ast::Step::INDENT + @keyword.unpack('U*').length + ': '.length]
  else
    @name.split("\n").enum_for(:each_with_index).map do |line, line_number|
      if line_number == 0
        Ast::Step::INDENT + @keyword.unpack('U*').length + ': '.length + line.unpack('U*').length
      else
        Ast::Step::INDENT + Ast::Step::INDENT + line.unpack('U*').length
      end
    end
  end
end

#source_indent(text_length) ⇒ Object



56
57
58
# File 'lib/cucumber/ast/feature_element.rb', line 56

def source_indent(text_length)
  max_line_length - text_length
end

#source_tag_namesObject



69
70
71
# File 'lib/cucumber/ast/feature_element.rb', line 69

def source_tag_names
  (@tags.tag_names.to_a + (@feature ? @feature.source_tag_names.to_a : [])).uniq
end

#text_lengthObject



30
31
32
# File 'lib/cucumber/ast/feature_element.rb', line 30

def text_length
  name_line_lengths.max
end