Method: Beaker::DSL::Structure#manual_step

Defined in:
lib/beaker/dsl/structure.rb

#manual_step(step_name) ⇒ Object

Provides a method to help manual tests. So we can use beaker to set up the environment, then prompt a user to manually check the setup.

Parameters:

  • step_name (String)

    The name of the step to be logged.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/beaker/dsl/structure.rb', line 60

def manual_step step_name
  require 'readline'
  logger.notify "\n* #{step_name}\n"
  if(!@options.has_key?(:exec_manual_tests))
    # if the option -exec-manual-tests is not set then this has executed outside of a manual tests
    # so we raise an error to avoid issues
    raise('--exec-manual-tests option not set, this means a manual_step was used outside a manual_test')
  end

  set_current_step_name(step_name)
  # Here we prompt the user to tell us if the step passed or failed
  loop do 
    input = Readline.readline('Did this step pass, Y/n? ', true).squeeze(" ").strip.downcase
    if %w(y yes).include?(input)
      break
    elsif %w(n no).include?(input)
      # if the step failed, the user can enter a fail message.
      # we loops to ensure they give use a fail message
      fail_message = ''
      loop do
        fail_message = Readline.readline('What was the reason for failure? ', true).squeeze(" ").strip
        if fail_message == ''
          # if nothing is entered we tell the user to enter something
          puts "No reason for failure given, please enter reason for failure."
        else
          break
        end
      end
      raise Beaker::DSL::FailTest, fail_message
    else
      # if something other than Y or n is returned we ask them again
      puts "Please enter Y or n."
    end
  end
end