forked from bladerunnerlabs/blade-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step.rb
57 lines (48 loc) · 1.24 KB
/
step.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
# frozen_string_literal: true
require_relative 'execution_list.rb'
# Step - handle the test step
class Step
attr_reader :result
def initialize(step_config)
@step_config = step_config
@step_name = @step_config.keys.first
@times = @step_config[step_config.keys.first]['Times']
@times = 1 if @times.nil?
@execution_list = @step_config[step_config.keys.first]['Execute']
@result = true
end
def run
puts "Running #{@step_name} step #{@times} times..."
step_start_time = Time.now.to_f
@times.times { return false unless execute_single_step_iteration }
print_total_step_time(step_start_time, Time.now.to_f)
true
end
private
def print_total_step_time(start_time, end_time)
puts "#{@step_name} total time is: " + (end_time - start_time).to_s.yellow
puts
puts
end
def print_result(result)
if result == true
puts 'PASS'.green
else
puts 'FAIL'.red
end
end
def step_failed(exception)
puts exception
print_result(false)
@result = false
end
def execute_single_step_iteration
execution = ExecutionList.new(@step_name, @execution_list)
execution.run
print_result(true)
true
rescue TestStepException => e
step_failed(e)
false
end
end