-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathnotification_decorator.rb
More file actions
58 lines (48 loc) · 1.33 KB
/
notification_decorator.rb
File metadata and controls
58 lines (48 loc) · 1.33 KB
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
58
# frozen_string_literal: true
module RSpec
module Github
class NotificationDecorator
# See https://github.community/t/set-output-truncates-multiline-strings/16852/3.
ESCAPE_MAP = {
'%' => '%25',
"\n" => '%0A',
"\r" => '%0D'
}.freeze
def initialize(notification)
@notification = notification
end
def line
location[1]
end
def annotation
"#{example.full_description}\n\n#{message}"
.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
end
def path
# TODO: use `delete_prefix` when dropping ruby 2.4 support
File.realpath(location[0]).sub(/\A#{workspace}#{File::SEPARATOR}/, '')
end
private
def example
@notification.example
end
def message
if @notification.respond_to?(:message_lines)
@notification.message_lines.join("\n")
else
"#{example.skip ? 'Skipped' : 'Pending'}: #{example.execution_result.pending_message}"
end
end
def location
if @notification.respond_to?(:exception)
@notification.exception.backtrace.first.split(':')
else
example.location.split(':')
end
end
def workspace
File.realpath(ENV.fetch('GITHUB_WORKSPACE', '.'))
end
end
end
end