spectre-core 1.12.0 → 1.12.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,143 +1,143 @@
1
- require 'ectoplasm'
2
-
3
- module Spectre
4
- module Logger
5
- class Console
6
- def initialize config
7
- raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'console'
8
-
9
- @config = config['log_format']['console']
10
- @indent = @config['indent'] || 2
11
- @width = @config['width'] || 80
12
- @fmt_end_context = @config['end_context']
13
- @fmt_sep = @config['separator']
14
- @fmt_start_group = @config['start_group']
15
- @fmt_end_group = @config['end_group']
16
-
17
- @process = nil
18
- @level = 0
19
- end
20
-
21
- def start_subject subject
22
- puts subject.desc.blue
23
- end
24
-
25
- def start_context context
26
- return unless context.__desc
27
-
28
- puts (' ' * indent) + context.__desc.magenta
29
- @level += 1
30
- end
31
-
32
- def end_context context
33
- return unless context.__desc
34
-
35
- @level -= 1
36
- puts (' ' * indent) + @fmt_end_context.gsub('<desc>', context.__desc).magenta if @fmt_end_context
37
- end
38
-
39
- def start_spec spec, data=nil
40
- text = spec.desc
41
- text += " with #{data}" if data
42
- puts (' ' * indent) + text.cyan
43
-
44
- @level += 1
45
- end
46
-
47
- def end_spec _spec, _data
48
- @level -= 1
49
- end
50
-
51
- def log_separator desc
52
- if desc
53
- desc = @fmt_sep.gsub('<indent>', ' ' * indent).gsub('<desc>', desc) if @fmt_sep
54
- puts desc.blue
55
- else
56
- puts
57
- end
58
- end
59
-
60
- def start_group desc
61
- desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
62
- puts (' ' * indent) + desc.blue
63
- @level += 1
64
- end
65
-
66
- def end_group desc
67
- if desc and @fmt_start_group
68
- desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
69
- puts (' ' * indent) + desc.blue
70
- end
71
-
72
- @level -= 1
73
- end
74
-
75
- def log_process desc
76
- print_line(desc)
77
- @process = desc
78
- @level += 1
79
- end
80
-
81
- def log_status _desc, status, annotation=nil
82
- status = status.green if status == Status::OK
83
- status = status.blue if status == Status::INFO
84
- status = status.grey if status == Status::DEBUG
85
- status = status.red if status == Status::FAILED
86
- status = status.red if status == Status::ERROR
87
- status = status.grey if status == Status::SKIPPED
88
-
89
- txt = status
90
- txt += ' ' + annotation if annotation
91
-
92
- @level -= 1
93
-
94
- if @process
95
- puts txt
96
- else
97
- print_line('', status)
98
- end
99
-
100
- @process = nil
101
- end
102
-
103
- def log_info message
104
- print_line(message, Status::INFO.blue)
105
- end
106
-
107
- def log_debug message
108
- print_line(message, Status::DEBUG.grey)
109
- end
110
-
111
- def log_error _spec, exception
112
- txt = (Status::ERROR + ' - ' + exception.class.name).red
113
- print_line('', txt)
114
- end
115
-
116
- def log_skipped _spec
117
- print_line('', Status::SKIPPED.grey)
118
- end
119
-
120
- private
121
-
122
- def indent
123
- (@level+1) * @indent
124
- end
125
-
126
- def print_line text='', status=nil
127
- puts if @process
128
-
129
- ind = indent
130
- line = (' ' * indent) + text
131
- remaining = @width - text.length - ind
132
- line += '.' * (@width - text.length - ind) if remaining > 0
133
-
134
- print line
135
-
136
- if status
137
- puts status
138
- @process = nil
139
- end
140
- end
141
- end
142
- end
143
- end
1
+ require 'ectoplasm'
2
+
3
+ module Spectre
4
+ module Logger
5
+ class Console
6
+ def initialize config
7
+ raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'console'
8
+
9
+ @config = config['log_format']['console']
10
+ @indent = @config['indent'] || 2
11
+ @width = @config['width'] || 80
12
+ @fmt_end_context = @config['end_context']
13
+ @fmt_sep = @config['separator']
14
+ @fmt_start_group = @config['start_group']
15
+ @fmt_end_group = @config['end_group']
16
+
17
+ @process = nil
18
+ @level = 0
19
+ end
20
+
21
+ def start_subject subject
22
+ puts subject.desc.blue
23
+ end
24
+
25
+ def start_context context
26
+ return unless context.__desc
27
+
28
+ puts (' ' * indent) + context.__desc.magenta
29
+ @level += 1
30
+ end
31
+
32
+ def end_context context
33
+ return unless context.__desc
34
+
35
+ @level -= 1
36
+ puts (' ' * indent) + @fmt_end_context.gsub('<desc>', context.__desc).magenta if @fmt_end_context
37
+ end
38
+
39
+ def start_spec spec, data=nil
40
+ text = spec.desc
41
+ text += " with #{data}" if data
42
+ puts (' ' * indent) + text.cyan
43
+
44
+ @level += 1
45
+ end
46
+
47
+ def end_spec _spec, _data
48
+ @level -= 1
49
+ end
50
+
51
+ def log_separator desc
52
+ if desc
53
+ desc = @fmt_sep.gsub('<indent>', ' ' * indent).gsub('<desc>', desc) if @fmt_sep
54
+ puts desc.blue
55
+ else
56
+ puts
57
+ end
58
+ end
59
+
60
+ def start_group desc
61
+ desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
62
+ puts (' ' * indent) + desc.blue
63
+ @level += 1
64
+ end
65
+
66
+ def end_group desc
67
+ if desc and @fmt_start_group
68
+ desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
69
+ puts (' ' * indent) + desc.blue
70
+ end
71
+
72
+ @level -= 1
73
+ end
74
+
75
+ def log_process desc
76
+ print_line(desc)
77
+ @process = desc
78
+ @level += 1
79
+ end
80
+
81
+ def log_status _desc, status, annotation=nil
82
+ status = status.green if status == Status::OK
83
+ status = status.blue if status == Status::INFO
84
+ status = status.grey if status == Status::DEBUG
85
+ status = status.red if status == Status::FAILED
86
+ status = status.red if status == Status::ERROR
87
+ status = status.grey if status == Status::SKIPPED
88
+
89
+ txt = status
90
+ txt += ' ' + annotation if annotation
91
+
92
+ @level -= 1
93
+
94
+ if @process
95
+ puts txt
96
+ else
97
+ print_line('', status)
98
+ end
99
+
100
+ @process = nil
101
+ end
102
+
103
+ def log_info message
104
+ print_line(message, Status::INFO.blue)
105
+ end
106
+
107
+ def log_debug message
108
+ print_line(message, Status::DEBUG.grey)
109
+ end
110
+
111
+ def log_error _spec, exception
112
+ txt = (Status::ERROR + ' - ' + exception.class.name).red
113
+ print_line('', txt)
114
+ end
115
+
116
+ def log_skipped _spec
117
+ print_line('', Status::SKIPPED.grey)
118
+ end
119
+
120
+ private
121
+
122
+ def indent
123
+ (@level+1) * @indent
124
+ end
125
+
126
+ def print_line text='', status=nil
127
+ puts if @process
128
+
129
+ ind = indent
130
+ line = (' ' * indent) + text
131
+ remaining = @width - text.length - ind
132
+ line += '.' * (@width - text.length - ind) if remaining > 0
133
+
134
+ print line
135
+
136
+ if status
137
+ puts status
138
+ @process = nil
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,96 +1,96 @@
1
- module Spectre
2
- module Logger
3
- class File
4
- def initialize config
5
- raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'file'
6
-
7
- @config = config['log_format']['file']
8
- @fmt_start_group = @config['start_group']
9
- @fmt_end_group = @config['end_group']
10
- @fmt_sep = @config['separator']
11
-
12
- @file_log = ::Logger.new config['log_file'], progname: 'spectre'
13
- @file_log.level = config['debug'] ? 'DEBUG' : 'INFO'
14
- end
15
-
16
- def start_subject subject
17
- @file_log.debug "start running subject '#{subject.desc}'"
18
- end
19
-
20
- def end_subject subject
21
- @file_log.debug "subject '#{subject.desc}' finished"
22
- end
23
-
24
- def start_context context
25
- if context and context.__desc
26
- @file_log.debug "start running context '#{context.__desc}'"
27
- else
28
- @file_log.debug "start running main context of #{context.__subject.desc}"
29
- end
30
- end
31
-
32
- def end_context context
33
- if context and context.__desc
34
- @file_log.debug "context '#{context.__desc}' finished"
35
- else
36
- @file_log.debug "main context finished of #{context.__subject.desc}"
37
- end
38
- end
39
-
40
- def start_spec spec, data=nil
41
- log_msg = "start running spec [#{spec.name}] '#{spec.desc}'"
42
- log_msg += " with data #{data}" if data
43
- @file_log.debug log_msg
44
- end
45
-
46
- def end_spec spec, data=nil
47
- log_msg = "running spec [#{spec.name}] '#{spec.desc}'"
48
- log_msg += " with data #{data}" if data
49
- log_msg += " finished"
50
- @file_log.debug log_msg
51
- end
52
-
53
- def log_separator desc
54
- desc = @fmt_sep.gsub('<desc>', desc) if @fmt_sep
55
- @file_log.info desc
56
- end
57
-
58
- def start_group desc
59
- desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
60
- @file_log.info desc
61
- end
62
-
63
- def end_group desc
64
- desc = @fmt_end_group.gsub('<desc>', desc) if @fmt_end_group
65
- @file_log.info desc
66
- end
67
-
68
- def log_process desc
69
- @file_log.debug desc
70
- end
71
-
72
- def log_info message
73
- @file_log.info "#{Status::INFO} #{message}"
74
- end
75
-
76
- def log_debug message
77
- @file_log.debug "#{Status::DEBUG} #{message}"
78
- end
79
-
80
- def log_error spec, exception
81
- file, line = exception.backtrace[0].match(/(.*\.rb):(\d+)/).captures
82
- @file_log.error "An unexpected error occured at '#{file}:#{line}' while running spec '#{spec.name}': [#{exception.class}] #{exception.message}\n#{exception.backtrace.join "\n"}"
83
- end
84
-
85
- def log_skipped spec
86
- @file_log.warn "spec '#{spec.desc}' canceled by user"
87
- end
88
-
89
- def log_status desc, status, annotation=nil
90
- msg = "expected #{desc}...#{status.upcase}"
91
- msg += " - #{annotation}" if annotation
92
- @file_log.debug msg
93
- end
94
- end
95
- end
96
- end
1
+ module Spectre
2
+ module Logger
3
+ class File
4
+ def initialize config
5
+ raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'file'
6
+
7
+ @config = config['log_format']['file']
8
+ @fmt_start_group = @config['start_group']
9
+ @fmt_end_group = @config['end_group']
10
+ @fmt_sep = @config['separator']
11
+
12
+ @file_log = ::Logger.new config['log_file'], progname: 'spectre'
13
+ @file_log.level = config['debug'] ? 'DEBUG' : 'INFO'
14
+ end
15
+
16
+ def start_subject subject
17
+ @file_log.debug "start running subject '#{subject.desc}'"
18
+ end
19
+
20
+ def end_subject subject
21
+ @file_log.debug "subject '#{subject.desc}' finished"
22
+ end
23
+
24
+ def start_context context
25
+ if context and context.__desc
26
+ @file_log.debug "start running context '#{context.__desc}'"
27
+ else
28
+ @file_log.debug "start running main context of #{context.__subject.desc}"
29
+ end
30
+ end
31
+
32
+ def end_context context
33
+ if context and context.__desc
34
+ @file_log.debug "context '#{context.__desc}' finished"
35
+ else
36
+ @file_log.debug "main context finished of #{context.__subject.desc}"
37
+ end
38
+ end
39
+
40
+ def start_spec spec, data=nil
41
+ log_msg = "start running spec [#{spec.name}] '#{spec.desc}'"
42
+ log_msg += " with data #{data}" if data
43
+ @file_log.debug log_msg
44
+ end
45
+
46
+ def end_spec spec, data=nil
47
+ log_msg = "running spec [#{spec.name}] '#{spec.desc}'"
48
+ log_msg += " with data #{data}" if data
49
+ log_msg += " finished"
50
+ @file_log.debug log_msg
51
+ end
52
+
53
+ def log_separator desc
54
+ desc = @fmt_sep.gsub('<desc>', desc) if @fmt_sep
55
+ @file_log.info desc
56
+ end
57
+
58
+ def start_group desc
59
+ desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
60
+ @file_log.info desc
61
+ end
62
+
63
+ def end_group desc
64
+ desc = @fmt_end_group.gsub('<desc>', desc) if @fmt_end_group
65
+ @file_log.info desc
66
+ end
67
+
68
+ def log_process desc
69
+ @file_log.debug desc
70
+ end
71
+
72
+ def log_info message
73
+ @file_log.info "#{Status::INFO} #{message}"
74
+ end
75
+
76
+ def log_debug message
77
+ @file_log.debug "#{Status::DEBUG} #{message}"
78
+ end
79
+
80
+ def log_error spec, exception
81
+ file, line = exception.backtrace[0].match(/(.*\.rb):(\d+)/).captures
82
+ @file_log.error "An unexpected error occurred at '#{file}:#{line}' while running spec '#{spec.name}': [#{exception.class}] #{exception.message}\n#{exception.backtrace.join "\n"}"
83
+ end
84
+
85
+ def log_skipped spec
86
+ @file_log.warn "spec '#{spec.desc}' canceled by user"
87
+ end
88
+
89
+ def log_status desc, status, annotation=nil
90
+ msg = "expected #{desc}...#{status.upcase}"
91
+ msg += " - #{annotation}" if annotation
92
+ @file_log.debug msg
93
+ end
94
+ end
95
+ end
96
+ end