rspec-ci-prettify 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4814566aeb1130a8ca2d63035a0664b8120753d608c280270f3e2369141033d
|
4
|
+
data.tar.gz: f2ee21c3127d7e5fc789994ee2efc75baafc0848ee81fda995f57c57e0ce96f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe45b373da2386e1a681535cb062c7d93637e6dd03708c76fd678349046a3e1228ff14af78aad34999387821b1d07c6a65534d7ea7b26778c0a88dfe14ae2028
|
7
|
+
data.tar.gz: 776c156d70fa5bcd18342c165bcb6698b45c4e2f8fba2e3aec66299eecc0dbcd08896d7b7f050330720d95122a57f173875b1c4106be660acd4eb53514102a48
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module RSpec
|
3
|
+
module Ci
|
4
|
+
module Prettify
|
5
|
+
class Annotation
|
6
|
+
def initialize(notification)
|
7
|
+
@notification = notification
|
8
|
+
@example = notification.example
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :example, :notification
|
12
|
+
|
13
|
+
def line
|
14
|
+
location.split(':')[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def error
|
18
|
+
msg = notification.message_lines.join("\n")
|
19
|
+
format_annotation_err(msg)
|
20
|
+
end
|
21
|
+
|
22
|
+
def file
|
23
|
+
File.realpath(location.split(':')[0]).sub(/\A#{github_workspace_file_path}#{File::SEPARATOR}/, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def format_annotation_err(str)
|
29
|
+
stripped_str = strip_ansi_colours(str)
|
30
|
+
formatted_str = stripped_str.gsub("\n", '').gsub('"', "'")
|
31
|
+
formatted_str.squeeze(" ")
|
32
|
+
end
|
33
|
+
|
34
|
+
# running --force-color for rspec for a more readable CI
|
35
|
+
# output works great but unfortunately ANSI colours dont
|
36
|
+
# get parsed properly on github annotations therefore
|
37
|
+
# make them harder to read. Stripping any ANSI colours
|
38
|
+
# on annotations here gives us the best of both worlds
|
39
|
+
# readable annotations and readable coloured CI
|
40
|
+
def strip_ansi_colours(str)
|
41
|
+
str.gsub(/\e\[(\d+)(;\d+)*m/, '')
|
42
|
+
end
|
43
|
+
|
44
|
+
def github_workspace_file_path
|
45
|
+
File.realpath(ENV.fetch('GITHUB_WORKSPACE', '.'))
|
46
|
+
end
|
47
|
+
|
48
|
+
def location
|
49
|
+
example.location
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -4,6 +4,7 @@ require 'rspec/core'
|
|
4
4
|
require 'rspec/core/formatters/base_formatter'
|
5
5
|
require 'rspec/core/formatters/console_codes'
|
6
6
|
require_relative 'constants'
|
7
|
+
require_relative 'annotation'
|
7
8
|
|
8
9
|
module RSpec
|
9
10
|
module Ci
|
@@ -17,38 +18,43 @@ module RSpec
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def dump_summary(summary)
|
20
|
-
@output <<
|
21
|
-
@output <<
|
21
|
+
@output << "\n\n"
|
22
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap(RSpec::Ci::Prettify::Constants::SEPARATOR, :bold_white)
|
23
|
+
@output << "\n\n"
|
24
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap('SUMMARY:', :cyan)
|
22
25
|
|
23
26
|
build_summary(summary)
|
24
27
|
end
|
25
28
|
|
26
29
|
def dump_pending(notification)
|
27
|
-
@output <<
|
28
|
-
@output <<
|
30
|
+
@output << "\n\n"
|
31
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap(RSpec::Ci::Prettify::Constants::SEPARATOR, :bold_white)
|
32
|
+
@output << "\n\n"
|
33
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap('PENDING:', :pending)
|
34
|
+
@output << "\n\n\t"
|
29
35
|
|
30
36
|
@output << notification.pending_examples.map do |example|
|
31
|
-
|
37
|
+
RSpec::Core::Formatters::ConsoleCodes.wrap(format_example_summary(example), :pending)
|
32
38
|
end.join("\n\t")
|
33
39
|
end
|
34
40
|
|
35
41
|
def dump_failures(notification)
|
36
|
-
@output <<
|
37
|
-
@output <<
|
42
|
+
@output << "\n\n"
|
43
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap(RSpec::Ci::Prettify::Constants::SEPARATOR, :bold_white)
|
44
|
+
@output << "\n\n"
|
45
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap('FAILURES:', :failure)
|
46
|
+
@output << "\n\n\t"
|
38
47
|
@output << failed_examples_output(notification)
|
39
48
|
end
|
40
49
|
|
41
|
-
def
|
42
|
-
|
50
|
+
def example_failed(notification)
|
51
|
+
annotation = RSpec::Ci::Prettify::Annotation.new(notification)
|
52
|
+
output << "\n::error file=#{annotation.file},line=#{annotation.line}::#{annotation.error}"
|
43
53
|
end
|
44
54
|
|
45
|
-
def
|
46
|
-
# @output << RSpec::Core::Formatters::ConsoleCodes.wrap("F", :failure)
|
47
|
-
end
|
55
|
+
def example_passed(_example); end
|
48
56
|
|
49
|
-
def example_pending(
|
50
|
-
# @output << RSpec::Core::Formatters::ConsoleCodes.wrap("*", :pending)
|
51
|
-
end
|
57
|
+
def example_pending(_example); end
|
52
58
|
|
53
59
|
def close(_notification)
|
54
60
|
@output << "\n"
|
@@ -63,44 +69,49 @@ module RSpec
|
|
63
69
|
|
64
70
|
failure_count = summary.failed_examples.count
|
65
71
|
pass_count = total_tests_ran - failure_count
|
66
|
-
|
72
|
+
@output << "\n"
|
67
73
|
@output << build_test_suite_duration(summary, total_tests_ran)
|
74
|
+
@output << "\n"
|
68
75
|
@output << build_pending_summary(pending_count, total_test_count)
|
69
76
|
|
70
77
|
if pass_count == total_tests_ran
|
71
|
-
@output <<
|
78
|
+
@output << "\n"
|
79
|
+
@output << RSpec::Core::Formatters::ConsoleCodes.wrap("All #{total_tests_ran} tests ran passed!!!",
|
80
|
+
:magenta)
|
72
81
|
return
|
73
82
|
end
|
74
|
-
|
83
|
+
@output << "\n"
|
75
84
|
@output << build_failure_summary(failure_count, total_tests_ran)
|
85
|
+
@output << "\n"
|
76
86
|
@output << build_pass_summary(pass_count, total_tests_ran)
|
87
|
+
@output << "\n"
|
77
88
|
end
|
78
89
|
|
79
90
|
def build_test_suite_duration(summary, test_run_count)
|
80
91
|
duration = RSpec::Core::Formatters::Helpers.format_duration(summary.duration)
|
81
|
-
duration_text = "
|
92
|
+
duration_text = "Ran #{test_run_count} tests overall in #{duration}."
|
82
93
|
|
83
|
-
|
94
|
+
RSpec::Core::Formatters::ConsoleCodes.wrap(duration_text, :cyan)
|
84
95
|
end
|
85
96
|
|
86
97
|
def build_pending_summary(pending_count, total_test_count)
|
87
98
|
pending_percentage = percentage_of_examples(pending_count, total_test_count)
|
88
|
-
|
89
|
-
|
99
|
+
|
100
|
+
pending_summary = "#{pending_percentage} of tests skipped/pending (#{pending_count})"
|
101
|
+
indent(RSpec::Core::Formatters::ConsoleCodes.wrap(pending_summary, :pending), 4)
|
90
102
|
end
|
91
103
|
|
92
104
|
def build_failure_summary(failure_count, total_tests_ran)
|
93
105
|
failure_percentage = percentage_of_examples(failure_count, total_tests_ran)
|
94
|
-
failure_summary = "
|
95
|
-
indent(
|
106
|
+
failure_summary = "#{failure_percentage} of tests failed (#{failure_count})"
|
107
|
+
indent(RSpec::Core::Formatters::ConsoleCodes.wrap(failure_summary, :failure), 4)
|
96
108
|
end
|
97
109
|
|
98
110
|
def build_pass_summary(pass_count, total_tests_ran)
|
99
111
|
pass_percentage = percentage_of_examples(pass_count, total_tests_ran)
|
112
|
+
pass_summary = "#{pass_percentage} of tests passed (#{pass_count})"
|
100
113
|
|
101
|
-
pass_summary
|
102
|
-
|
103
|
-
indent(format_colour(pass_summary, :success), 4)
|
114
|
+
indent(RSpec::Core::Formatters::ConsoleCodes.wrap(pass_summary, :success), 4)
|
104
115
|
end
|
105
116
|
|
106
117
|
def percentage_of_examples(count, total)
|
@@ -120,10 +131,6 @@ module RSpec
|
|
120
131
|
output.join("\n\n\t")
|
121
132
|
end
|
122
133
|
|
123
|
-
def format_colour(str, status)
|
124
|
-
RSpec::Core::Formatters::ConsoleCodes.wrap(str, status)
|
125
|
-
end
|
126
|
-
|
127
134
|
def format_example_summary(example)
|
128
135
|
full_description = example.full_description
|
129
136
|
location = example.location
|
@@ -132,10 +139,11 @@ module RSpec
|
|
132
139
|
|
133
140
|
def failed_example_output(example)
|
134
141
|
msg = example.execution_result.exception.message
|
135
|
-
|
136
|
-
|
142
|
+
sanitized_err_message = sanitize_msg(msg)
|
143
|
+
formatted_err_message = RSpec::Core::Formatters::ConsoleCodes.wrap(sanitized_err_message, :failure)
|
144
|
+
summary = RSpec::Core::Formatters::ConsoleCodes.wrap(format_example_summary(example), :failure)
|
137
145
|
|
138
|
-
"#{summary} \n #{formatted_err_message}"
|
146
|
+
"#{summary} \n #{formatted_err_message} \n"
|
139
147
|
end
|
140
148
|
|
141
149
|
def sanitize_msg(msg)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-ci-prettify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jjholmes927
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- lib/rspec/ci/prettify.rb
|
63
|
+
- lib/rspec/ci/prettify/annotation.rb
|
63
64
|
- lib/rspec/ci/prettify/constants.rb
|
64
65
|
- lib/rspec/ci/prettify/formatter.rb
|
65
66
|
- lib/rspec/ci/prettify/version.rb
|