Module: Cucumber::Ast::HasSteps

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

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

Returns the value of attribute gherkin_statement.



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

def gherkin_statement
  @gherkin_statement
end

#raw_stepsObject (readonly)

Returns the value of attribute raw_steps.



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

def raw_steps
  @raw_steps
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#accept_hook?(hook) ⇒ Boolean

Returns:

  • (Boolean)


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

def accept_hook?(hook)
  Gherkin::TagExpression.new(hook.tag_expressions).evaluate(source_tags)
end

#attach_steps(steps) ⇒ Object



12
13
14
15
16
# File 'lib/cucumber/ast/has_steps.rb', line 12

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

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



44
45
46
# File 'lib/cucumber/ast/has_steps.rb', line 44

def backtrace_line(step_name = "#{@keyword}: #{name}", line = self.line)
  "#{location.on_line(line)}:in `#{step_name}'"
end

#first_line_lengthObject



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

def first_line_length
  name_line_lengths[0]
end

#languageObject



68
69
70
# File 'lib/cucumber/ast/has_steps.rb', line 68

def language
  @language || raise("Language is required for a #{self.class}")
end

#matches_scenario_names?(scenario_name_regexps) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cucumber/ast/has_steps.rb', line 40

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

#max_line_lengthObject



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

def max_line_length
  steps.max_line_length(self)
end

#name_line_lengthsObject



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

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



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

def source_indent(text_length)
  max_line_length - text_length
end

#source_tag_namesObject



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

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

#source_tagsObject



64
65
66
# File 'lib/cucumber/ast/has_steps.rb', line 64

def source_tags
  @tags.tags.to_a + feature_tags.tags.to_a
end

#text_lengthObject



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

def text_length
  name_line_lengths.max
end