moto 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/result.rb DELETED
@@ -1,84 +0,0 @@
1
- module Moto
2
- class Result
3
-
4
- PENDING = :pending # -2
5
- RUNNING = :running # -1
6
- PASSED = :passed # 0
7
- FAILURE = :failure # 1
8
- ERROR = :error # 2
9
- SKIPPED = :skipped # 3
10
-
11
- attr_reader :summary
12
-
13
- def [](key)
14
- @results[key]
15
- end
16
-
17
- def all
18
- @results
19
- end
20
-
21
- def initialize(runner)
22
- @runner = runner
23
- @results = {}
24
- @summary = {}
25
- end
26
-
27
- def start_run
28
- # start timer
29
- @summary[:started_at] = Time.now.to_f
30
- end
31
-
32
- def end_run
33
- # info about duration and overall execution result
34
- @summary[:finished_at] = Time.now.to_f
35
- @summary[:duration] = @summary[:finished_at] - @summary[:started_at]
36
- @summary[:result] = PASSED
37
- @summary[:result] = FAILURE unless @results.values.select{ |v| v[:failures].count > 0 }.empty?
38
- @summary[:result] = ERROR unless @results.values.select{ |v| v[:result] == ERROR }.empty?
39
- @summary[:cnt_all] = @results.count
40
- @summary[:tests_passed] = @results.select{ |k,v| v[:result] == PASSED }
41
- @summary[:tests_failure] = @results.select{ |k,v| v[:result] == FAILURE }
42
- @summary[:tests_error] = @results.select{ |k,v| v[:result] == ERROR }
43
- @summary[:tests_skipped] = @results.select{ |k,v| v[:result] == SKIPPED }
44
- @summary[:cnt_passed] = @summary[:tests_passed].count
45
- @summary[:cnt_failure] = @summary[:tests_failure].count
46
- @summary[:cnt_error] = @summary[:tests_error].count
47
- @summary[:cnt_skipped] = @summary[:tests_skipped].count
48
- end
49
-
50
- def start_test(test)
51
- @results[test.name] = { class: test.class, result: RUNNING, env: test.env, params: test.params, name: test.name, error: nil, failures: [], started_at: Time.now.to_f }
52
- end
53
-
54
- def end_test(test)
55
- # calculate result basing on errors/failures
56
- @results[test.name][:finished_at] = Time.now.to_f
57
- test.result = PASSED
58
- test.result = FAILURE unless @results[test.name][:failures].empty?
59
- unless @results[test.name][:error].nil?
60
- if @results[test.name][:error].is_a? Moto::Exceptions::TestSkipped
61
- test.result = SKIPPED
62
- elsif @results[test.name][:error].is_a? Moto::Exceptions::TestForcedPassed
63
- test.result = PASSED
64
- elsif @results[test.name][:error].is_a? Moto::Exceptions::TestForcedFailure
65
- add_failure(test, @results[test.name][:error].message)
66
- test.result = FAILURE
67
- else
68
- test.result = ERROR
69
- end
70
- end
71
- @results[test.name][:duration] = @results[test.name][:finished_at] - @results[test.name][:started_at]
72
- @results[test.name][:result] = test.result
73
- end
74
-
75
- def add_failure(test, msg)
76
- @results[test.name][:failures] << msg
77
- end
78
-
79
- def add_error(test, e)
80
- @results[test.name][:error] = e
81
- end
82
-
83
- end
84
- end
data/lib/test.rb DELETED
@@ -1,107 +0,0 @@
1
- module Moto
2
- class Test
3
-
4
- include Moto::Assert
5
- include Moto::ForwardContextMethods
6
-
7
- attr_writer :context
8
- attr_accessor :result
9
- attr_reader :name
10
- attr_reader :env
11
- attr_reader :params
12
- attr_accessor :static_path
13
- attr_accessor :log_path
14
- attr_accessor :evaled
15
-
16
- class << self
17
- attr_accessor :_path
18
- end
19
-
20
- def self.inherited(k)
21
- k._path = caller.first.match( /(.+):\d+:in/ )[1]
22
- end
23
-
24
- def path
25
- self.class._path
26
- end
27
-
28
- def initialize
29
- # @context = context
30
- @result = Moto::Result::PENDING
31
- end
32
-
33
- def init(env, params, params_index)
34
- @env = env
35
- @params = params
36
- set_name(params_index)
37
- end
38
-
39
- # Sets name of the test based on its properties:
40
- # - number/name of currently executed configuration run
41
- # - env
42
- def set_name(params_index)
43
- if @env == :__default
44
- return @name = "#{self.class.to_s}" if @params.empty?
45
- return @name = "#{self.class.to_s}/#{@params['__name']}" if @params.key?('__name')
46
- return @name = "#{self.class.to_s}/params_#{params_index}" unless @params.key?('__name')
47
- else
48
- return @name = "#{self.class.to_s}/#{@env}" if @params.empty?
49
- return @name = "#{self.class.to_s}/#{@env}/#{@params['__name']}" if @params.key?('__name')
50
- return @name = "#{self.class.to_s}/#{@env}/params_#{params_index}" unless @params.key?('__name')
51
- end
52
- @name = self.class.to_s
53
- end
54
- private :set_name
55
-
56
- def dir
57
- # puts self.class.path
58
- return File.dirname(@static_path) unless @static_path.nil?
59
- File.dirname(self.path)
60
- end
61
-
62
- def filename
63
- return File.basename(@static_path, ".*") unless @static_path.nil?
64
- File.basename(path, ".*")
65
- end
66
-
67
- def run
68
- # abstract
69
- end
70
-
71
- def before
72
- # abstract
73
- end
74
-
75
- def after
76
- # abstract
77
- end
78
-
79
- def skip(msg = nil)
80
- if msg.nil?
81
- msg = "Test skipped with no reason given."
82
- else
83
- msg = "Skip reason: #{msg}"
84
- end
85
- raise Exceptions::TestSkipped.new msg
86
- end
87
-
88
- def fail(msg = nil)
89
- if msg.nil?
90
- msg = "Test forcibly failed with no reason given."
91
- else
92
- msg = "Forced failure, reason: #{msg}"
93
- end
94
- raise Exceptions::TestForcedFailure.new msg
95
- end
96
-
97
- def pass(msg = nil)
98
- if msg.nil?
99
- msg = "Test forcibly passed with no reason given."
100
- else
101
- msg = "Forced passed, reason: #{msg}"
102
- end
103
- raise Exceptions::TestForcedPassed.new msg
104
- end
105
-
106
- end
107
- end