class Lucid::AST::Step

Constants

INDENT

Attributes

exception[RW]
feature_element[RW]
gherkin_statement[R]
keyword[R]
language[R]
multiline_arg[RW]
name[R]
options[W]
step_collection[W]

Public Class Methods

new(language, location, keyword, name, multiline_arg=nil) click to toggle source
# File lib/lucid/ast/step.rb, line 16
def initialize(language, location, keyword, name, multiline_arg=nil)
  @language, @location, @keyword, @name, @multiline_arg = language, location, keyword, name, multiline_arg
  @language || raise('Language is required.')
end

Public Instance Methods

accept(visitor) click to toggle source
# File lib/lucid/ast/step.rb, line 49
def accept(visitor)
  # The only time a Step is visited is when it is in a ScenarioOutline.
  # Otherwise it's always StepInvocation that gets visited instead.
  visitor.visit_step(self) do
    status = :skipped
    exception = nil
    background = nil
    step_result = StepResult.new(keyword, first_match(visitor), @multiline_arg, status, exception, source_indent, background, file_colon_line)
    step_result.accept(visitor)
  end

end
background?() click to toggle source
# File lib/lucid/ast/step.rb, line 26
def background?
  false
end
backtrace_line() click to toggle source
# File lib/lucid/ast/step.rb, line 86
def backtrace_line
  @backtrace_line ||= feature_element.backtrace_line("#{keyword}#{name}", line) unless feature_element.nil?
end
dom_id() click to toggle source
# File lib/lucid/ast/step.rb, line 90
def dom_id
  @dom_id ||= file_colon_line.gsub(/\//, '_').gsub(/\./, '_').gsub(/:/, '_')
end
first_match(visitor) click to toggle source
# File lib/lucid/ast/step.rb, line 62
def first_match(visitor)
  # The feature_element is always a ScenarioOutline in this case.
  feature_element.each_example_row do |cells|
    argument_hash       = cells.to_hash
    delimited_arguments = delimit_argument_names(argument_hash)
    name_to_match       = replace_name_arguments(delimited_arguments)
    step_match          = visitor.runtime.step_match(name_to_match, name) rescue nil
    return step_match if step_match
  end
  NoStepMatch.new(self, name)
end
source_indent() click to toggle source
# File lib/lucid/ast/step.rb, line 78
def source_indent
  feature_element.source_indent(text_length)
end
status() click to toggle source
# File lib/lucid/ast/step.rb, line 30
def status
  # Step always has status skipped, because Step is always in a ScenarioOutline
  :skipped
end
step_invocation() click to toggle source
# File lib/lucid/ast/step.rb, line 35
def step_invocation
  StepInvocation.new(self, name, @multiline_arg, [])
end
step_invocation_from_cells(cells) click to toggle source
# File lib/lucid/ast/step.rb, line 39
def step_invocation_from_cells(cells)
  matched_cells = matched_cells(cells)

  delimited_arguments = delimit_argument_names(cells.to_hash)
  name                = replace_name_arguments(delimited_arguments)
  multiline_arg       = @multiline_arg.nil? ? nil : @multiline_arg.arguments_replaced(delimited_arguments)

  StepInvocation.new(self, name, multiline_arg, matched_cells)
end
text_length(name=name) click to toggle source
# File lib/lucid/ast/step.rb, line 82
def text_length(name=name)
  INDENT + INDENT + keyword.unpack('U*').length + name.unpack('U*').length
end
to_sexp() click to toggle source
# File lib/lucid/ast/step.rb, line 74
def to_sexp
  [:step, line, keyword, name, (@multiline_arg.nil? ? nil : @multiline_arg.to_sexp)].compact
end

Private Instance Methods

delimit_argument_names(argument_hash) click to toggle source
# File lib/lucid/ast/step.rb, line 106
def delimit_argument_names(argument_hash)
  argument_hash.inject({}) { |h,(name,value)| h[delimited(name)] = value; h }
end
delimited(s) click to toggle source
# File lib/lucid/ast/step.rb, line 110
def delimited(s)
  "<#{s}>"
end
matched_cells(cells) click to toggle source
# File lib/lucid/ast/step.rb, line 96
def matched_cells(cells)
  col_index = 0
  cells.select do |cell|
    header_cell = cell.table.header_cell(col_index)
    col_index += 1
    delimited = delimited(header_cell.value)
    name.index(delimited) || (@multiline_arg && @multiline_arg.has_text?(delimited))
  end
end
replace_name_arguments(argument_hash) click to toggle source
# File lib/lucid/ast/step.rb, line 114
def replace_name_arguments(argument_hash)
  name_with_arguments_replaced = name
  argument_hash.each do |key, value|
    value ||= ''
    name_with_arguments_replaced = name_with_arguments_replaced.gsub(key, value)
  end
  name_with_arguments_replaced
end