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: 5a2e3078e3f88cb494342835d5dd5a82c8e7a5a55df5ea7dca66c0f34d22008d
4
- data.tar.gz: 9b570af8c0d2710379e801ea0a6239b588c5ea1e1fd4564194268c4bd462bf4d
3
+ metadata.gz: f4814566aeb1130a8ca2d63035a0664b8120753d608c280270f3e2369141033d
4
+ data.tar.gz: f2ee21c3127d7e5fc789994ee2efc75baafc0848ee81fda995f57c57e0ce96f1
5
5
  SHA512:
6
- metadata.gz: 425d510af634ee01ad47c3eb8e3c2289f2f2e7c1b099cec3aa6a52df29bb0531d93170828391768832b6335d8b6e8f57497c432ace485c3c14fd2490e127a3dd
7
- data.tar.gz: 5a1fef723c7ff99386fb14557bfb8a032936cf37ffad3f7361f68229fa2cb9378162e87f3f63aaa7adfbe324fa3f226b8562d3e970a042e93bb0d41cef1f26a8
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,7 +4,7 @@ module RSpec
4
4
  module Ci
5
5
  module Prettify
6
6
  module Constants
7
- SEPARATOR = "\n\n#{'-' * 55}"
7
+ SEPARATOR = "#{'-' * 55}"
8
8
  end
9
9
  end
10
10
  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 << RSpec::Ci::Prettify::Constants::SEPARATOR
21
- @output << format_colour("\n\nSUMMARY:\n\t", :cyan)
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 << RSpec::Ci::Prettify::Constants::SEPARATOR
28
- @output << format_colour("\n\nPENDING:\n\t", :pending)
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
- format_colour(format_example_summary(example), :pending)
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 << RSpec::Ci::Prettify::Constants::SEPARATOR
37
- @output << format_colour("\n\nFAILURES:\n\t", :failure)
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 example_passed(example)
42
- # @output << RSpec::Core::Formatters::ConsoleCodes.wrap(".", :success)
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 example_failed(example)
46
- # @output << RSpec::Core::Formatters::ConsoleCodes.wrap("F", :failure)
47
- end
55
+ def example_passed(_example); end
48
56
 
49
- def example_pending(example)
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 << format_colour("\n All #{total_tests_ran} tests ran passed!!!", :magenta)
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 = "\nRan #{test_run_count} tests overall in #{duration}."
92
+ duration_text = "Ran #{test_run_count} tests overall in #{duration}."
82
93
 
83
- format_colour(duration_text, :cyan)
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
- pending_summary = "\n #{pending_percentage} of tests skipped/pending (#{pending_count})"
89
- indent(format_colour(pending_summary, :pending), 4)
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 = "\n #{failure_percentage} of tests failed (#{failure_count})"
95
- indent(format_colour(failure_summary, :failure), 4)
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 = "\n #{pass_percentage} of tests passed (#{pass_count})"
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
- formatted_err_message = sanitize_msg(msg)
136
- summary = format_colour(format_example_summary(example), :failure)
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)
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Ci
5
5
  module Prettify
6
- VERSION = '0.1.0'
6
+ VERSION = '0.3.0'
7
7
  end
8
8
  end
9
9
  end
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.1.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-02 00:00:00.000000000 Z
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