Class: Cucumber::Ast::Step

Inherits:
Object show all
Defined in:
lib/cucumber/ast/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, keyword, name, *multiline_args) ⇒ Step

Returns a new instance of Step.



11
12
13
# File 'lib/cucumber/ast/step.rb', line 11

def initialize(line, keyword, name, *multiline_args)
  @line, @keyword, @name, @multiline_args = line, keyword, name, multiline_args
end

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception.



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

def exception
  @exception
end

#keywordObject (readonly)

Returns the value of attribute keyword.



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

def keyword
  @keyword
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



8
9
10
# File 'lib/cucumber/ast/step.rb', line 8

def options=(value)
  @options = value
end

#previous=(value) ⇒ Object (writeonly)

Sets the attribute previous

Parameters:

  • value

    the value to set the attribute previous to.



8
9
10
# File 'lib/cucumber/ast/step.rb', line 8

def previous=(value)
  @previous = value
end

#scenarioObject

Returns the value of attribute scenario.



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

def scenario
  @scenario
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#world=(value) ⇒ Object (writeonly)

Sets the attribute world

Parameters:

  • value

    the value to set the attribute world to.



8
9
10
# File 'lib/cucumber/ast/step.rb', line 8

def world=(value)
  @world = value
end

Instance Method Details

#accept(visitor) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/cucumber/ast/step.rb', line 23

def accept(visitor)
  execute(visitor)
  visitor.visit_step_name(@keyword, @name, @status, @step_definition, source_indent)
  @multiline_args.each do |multiline_arg|
    visitor.visit_multiline_arg(multiline_arg, @status)
  end
  @exception
end

#actual_keywordObject



56
57
58
59
60
61
62
# File 'lib/cucumber/ast/step.rb', line 56

def actual_keyword
  if [Cucumber.keyword_hash['and'], Cucumber.keyword_hash['but']].index(@keyword) && previous_step
    previous_step.actual_keyword
  else
    @keyword
  end
end

#at_lines?(lines) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cucumber/ast/step.rb', line 36

def at_lines?(lines)
  lines.empty? || lines.index(@line) || @multiline_args.detect{|a| a.at_lines?(lines)}
end

#backtrace_lineObject



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

def backtrace_line
  @backtrace_line ||= @scenario.backtrace_line("#{@keyword} #{@name}", @line) unless @scenario.nil?
end

#execute_with_arguments(argument_hash, world, previous, visitor, row_line) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/cucumber/ast/step.rb', line 15

def execute_with_arguments(argument_hash, world, previous, visitor, row_line)
  delimited_arguments = delimit_argument_names(argument_hash)
  name                = replace_name_arguments(delimited_arguments)
  multiline_args      = replace_multiline_args_arguments(delimited_arguments)

  execute_twin(world, previous, visitor, row_line, name, *multiline_args)
end

#file_lineObject



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

def file_line
  @file_line ||= @scenario.file_line(@line) unless @scenario.nil?
end

#source_indentObject



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

def source_indent
  @scenario.source_indent(text_length)
end

#text_lengthObject



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

def text_length
  @keyword.jlength + @name.jlength + 2 # Add 2 because steps get indented 2 more than scenarios
end

#to_sexpObject



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

def to_sexp
  [:step, @line, @keyword, @name, *@multiline_args.map{|arg| arg.to_sexp}]
end