Class: CTT::Cli::Command::SuitesConfig
- Inherits:
-
Base
show all
- Includes:
- CTT::Cli, Interactive
- Defined in:
- lib/cli/commands/suites_configure.rb
Constant Summary
Constants included
from CTT::Cli
RESULTS_SERVER_URL, STATIC_COMMANDS, TEST_RESULT_FILE, TEST_SUITE_CONFIG_FILE, VERSION
Instance Method Summary
collapse
Constructor Details
#initialize(command, args, runner) ⇒ SuitesConfig
Returns a new instance of SuitesConfig.
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/cli/commands/suites_configure.rb', line 10
def initialize(command, args, runner)
super(args, runner)
pieces = command.split(" ")
pieces.insert(0, "list") if pieces.size == 1
@action, _ = pieces
@configs = @runner.configs
@suites = @runner.suites
end
|
Instance Method Details
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/cli/commands/suites_configure.rb', line 25
def add
puts "add suite"
location = ""
invalid_input = true
3.times do
user_input = ask("test suite source directory").strip
if user_input =~ /^~/
user_input = File.expand_path(user_input)
else
user_input = File.absolute_path(user_input)
end
if Dir.exist?(user_input)
if File.exist?(File.join(user_input, TEST_SUITE_CONFIG_FILE))
invalid_input = false
location = user_input
break
else
say("the configure file: #{yellow(TEST_SUITE_CONFIG_FILE)} " +
"cannot be found under #{user_input}.")
end
else
say("the directory: #{user_input} is invalid.")
end
end
if invalid_input
say("invalid inputs for 3 times. abort!", :red)
exit(1)
end
load_test_suite_config(location)
suite_alias = @suite_config["name"]
@suites.suites["suites"][suite_alias] = location
@suites.save
say("configure suite: #{suite_alias} successfully.", :green)
end
|
64
65
66
|
# File 'lib/cli/commands/suites_configure.rb', line 64
def list
print_suites
end
|
#load_test_suite_config(location) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/cli/commands/suites_configure.rb', line 68
def load_test_suite_config(location)
path = File.join(location, TEST_SUITE_CONFIG_FILE)
@suite_config = YAML.load_file(path)
unless @suite_config.is_a?(Hash)
say("#{path} is not valid yml file.", :red)
exit(1)
end
validate_points = %w(name commands results)
validate_points.each do |p|
unless @suite_config.keys.include?(p)
say("field: '#{p}' is not found in config file #{path}", :red)
exit(1)
end
end
end
|
#print_suites ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/cli/commands/suites_configure.rb', line 86
def print_suites
= ["alias", "path"]
rows = []
@suites.suites["suites"].each do |suite_alias, path|
rows << [suite_alias, path]
end
table = Terminal::Table.new(:headings => , :rows => rows)
puts table
end
|
21
22
23
|
# File 'lib/cli/commands/suites_configure.rb', line 21
def run
eval(@action)
end
|