Class: Cucumberator::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumberator/parser.rb

Constant Summary collapse

FULL_BACKTRACE =

for debugging

false

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.last_inputObject

Returns the value of attribute last_input.



9
10
11
# File 'lib/cucumberator/parser.rb', line 9

def last_input
  @last_input
end

Class Method Details

.command_runner_for(command) ⇒ Object



31
32
33
34
# File 'lib/cucumberator/parser.rb', line 31

def command_runner_for(command)
  full_klass_name = "Cucumberator::Commands::#{klass_name_for(command)}"
  constantize(full_klass_name)
end

.constantize(camel_cased_word) ⇒ Object

copied from ActiveSupport activesupport/lib/active_support/inflector/methods.rb



49
50
51
52
53
54
55
56
57
58
# File 'lib/cucumberator/parser.rb', line 49

def constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end

.execute_cucumber_step(input, world) ⇒ Object



40
41
42
43
44
45
# File 'lib/cucumberator/parser.rb', line 40

def execute_cucumber_step(input, world)
  return if input.to_s.empty?

  self.last_input = input
  world.steps(input)
end

.klass_name_for(command) ⇒ Object



36
37
38
# File 'lib/cucumberator/parser.rb', line 36

def klass_name_for(command)
  command.scan(/\w+/).map(&:capitalize).join
end

.parse_input(input, scenario, step_line, world, saved_stack) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cucumberator/parser.rb', line 11

def parse_input(input, scenario, step_line, world, saved_stack)
  if Cucumberator::Commands::AVAILABLE.include?(input)
    runner = command_runner_for(input)
    runner.perform(scenario, step_line, last_input, saved_stack)
  elsif input == ""
    Cucumberator::Commands::Save.save_empty_line(scenario, step_line, saved_stack)
  else
    try_to_execute(input, scenario, step_line, world, saved_stack)
    false
  end
end

.try_to_execute(input, scenario, step_line, world, saved_stack) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/cucumberator/parser.rb', line 23

def try_to_execute(input, scenario, step_line, world, saved_stack)
  execute_cucumber_step(input, world)
  Cucumberator::Commands::Save.perform(scenario, step_line, last_input, saved_stack)
rescue => e
  puts e.inspect
  puts e.backtrace.join("\n") if FULL_BACKTRACE
end