Module: ASAConsole::Test
- Defined in:
- lib/asa_console/test.rb,
lib/asa_console/test/script.rb
Overview
Methods to declare and execute ASAConsole test scripts in a lab environment.
Defined Under Namespace
Classes: Script
Class Method Summary collapse
-
.color_scheme=(scheme_key) ⇒ void
Set the color scheme for test script output.
-
.script {|asa| ... } ⇒ void
Declare a test script by passing a block to this method.
-
.start(test_file, terminal_opts, enable_password = nil, show_session_log = false) ⇒ Boolean
Load a ruby source file with test script declarations and execute them.
-
.test_names ⇒ Array
A list of test names that can be passed to the command line utility.
-
.test_path(test_name = nil) ⇒ String
Returns the absolute path of the test script directory or, if a test name is given, returns the path to the test file.
Class Method Details
.color_scheme=(scheme_key) ⇒ void
Set the color scheme for test script output.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/asa_console/test.rb', line 50 def self.color_scheme=(scheme_key) case scheme_key when :light @@colors = { prompt: "\e[1;36m", input: "\e[1;33m", output: "\e[1;32m", log: "\e[1;31m", info: "\e[1;35m" } when :dark @@colors = { prompt: "\e[0;36m", input: "\e[0;33m", output: "\e[0;32m", log: "\e[0;31m", info: "\e[0;35m" } else @@colors = {} end end |
.script {|asa| ... } ⇒ void
Declare a test script by passing a block to this method.
39 40 41 42 43 |
# File 'lib/asa_console/test.rb', line 39 def self.script(&block) klass = Class.new(Script) klass.send(:define_method, 'test!', &block) @@scripts << klass end |
.start(test_file, terminal_opts, enable_password = nil, show_session_log = false) ⇒ Boolean
Load a ruby source file with test script declarations and execute them.
The terminal_opts and enable_password parameters will be passed to a
ASAConsole factory method to generate a test object for each script run.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/asa_console/test.rb', line 114 def self.start(test_file, terminal_opts, enable_password = nil, show_session_log = false) begin require test_file rescue LoadError puts "Unable to load #{test_file}" return false end @@scripts.each do |klass| script = klass.new(terminal_opts, enable_password) script.run script.show_session_log if show_session_log puts puts colorize('Test Complete!', :info) puts end true end |
.test_names ⇒ Array
A list of test names that can be passed to the command line utility.
97 98 99 100 |
# File 'lib/asa_console/test.rb', line 97 def self.test_names names = Dir.glob(File.join(test_path, 'test_*.rb')) names.collect { |file| file.sub(/.*test_(.*)\.rb$/, '\1') }.sort end |
.test_path ⇒ String .test_path(test_name) ⇒ String
Returns the absolute path of the test script directory or, if a test name is given, returns the path to the test file.
88 89 90 91 92 |
# File 'lib/asa_console/test.rb', line 88 def self.test_path(test_name = nil) path = File.realpath(File.join(File.dirname(__FILE__), '..', '..', 'script')) path = File.join(path, "test_#{test_name}.rb") if test_name path end |