Class: Cucumberator::Input

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world, scenario, step_line = nil) ⇒ Input

Returns a new instance of Input.



8
9
10
11
12
13
14
15
16
# File 'lib/cucumberator/input.rb', line 8

def initialize(world, scenario, step_line = nil)
  @world, @scenario = world, scenario
  @step_line = step_line if step_line
  @saved_stack = []

  check_scenario
  set_autocomplete
  read_input
end

Instance Attribute Details

#exit_flagObject

Returns the value of attribute exit_flag.



6
7
8
# File 'lib/cucumberator/input.rb', line 6

def exit_flag
  @exit_flag
end

#last_inputObject

Returns the value of attribute last_input.



6
7
8
# File 'lib/cucumberator/input.rb', line 6

def last_input
  @last_input
end

#saved_stackObject

Returns the value of attribute saved_stack.



6
7
8
# File 'lib/cucumberator/input.rb', line 6

def saved_stack
  @saved_stack
end

#scenarioObject

Returns the value of attribute scenario.



6
7
8
# File 'lib/cucumberator/input.rb', line 6

def scenario
  @scenario
end

#step_lineObject

Returns the value of attribute step_line.



6
7
8
# File 'lib/cucumberator/input.rb', line 6

def step_line
  @step_line
end

#worldObject

Returns the value of attribute world.



6
7
8
# File 'lib/cucumberator/input.rb', line 6

def world
  @world
end

Instance Method Details

#check_scenarioObject



18
19
20
# File 'lib/cucumberator/input.rb', line 18

def check_scenario
  raise "Sorry, cucumberator is not available when scenario is already failing!" if scenario.failed?
end

#read_inputObject



22
23
24
25
26
# File 'lib/cucumberator/input.rb', line 22

def read_input
  input = Readline.readline("> ", true)
  exit_flag = Cucumberator::Parser.parse_input(input, scenario, step_line, world, saved_stack)
  read_input unless exit_flag
end

#set_autocompleteObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cucumberator/input.rb', line 28

def set_autocomplete
  commands = Cucumberator::Commands::AVAILABLE

  Cucumberator::Steps.new(scenario).all.each do |s|
    # remove typical start/end regexp parts
    step = s.gsub(/^\/\^|\$\/$/,'')
    # every step is equal, no matter if When/Then/And, so combining everything for autocomplete
    commands << "When #{step}" << "Then #{step}" << "And #{step}"
  end

  Readline.basic_word_break_characters = ""; # no break chars = no autobreaking for completion input
  Readline.completion_proc = proc { |s| commands.grep( /^#{Regexp.escape(s)}/ ) }
end