rspec-ci-prettify 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a2e3078e3f88cb494342835d5dd5a82c8e7a5a55df5ea7dca66c0f34d22008d
4
+ data.tar.gz: 9b570af8c0d2710379e801ea0a6239b588c5ea1e1fd4564194268c4bd462bf4d
5
+ SHA512:
6
+ metadata.gz: 425d510af634ee01ad47c3eb8e3c2289f2f2e7c1b099cec3aa6a52df29bb0531d93170828391768832b6335d8b6e8f57497c432ace485c3c14fd2490e127a3dd
7
+ data.tar.gz: 5a1fef723c7ff99386fb14557bfb8a032936cf37ffad3f7361f68229fa2cb9378162e87f3f63aaa7adfbe324fa3f226b8562d3e970a042e93bb0d41cef1f26a8
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Ci
5
+ module Prettify
6
+ module Constants
7
+ SEPARATOR = "\n\n#{'-' * 55}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/formatters/base_formatter'
5
+ require 'rspec/core/formatters/console_codes'
6
+ require_relative 'constants'
7
+
8
+ module RSpec
9
+ module Ci
10
+ module Prettify
11
+ class Formatter < RSpec::Core::Formatters::BaseFormatter
12
+ RSpec::Core::Formatters.register self, :dump_summary, :dump_pending, :dump_failures,
13
+ :example_passed, :example_failed, :example_pending, :close
14
+
15
+ def initialize(output)
16
+ @output = output
17
+ end
18
+
19
+ def dump_summary(summary)
20
+ @output << RSpec::Ci::Prettify::Constants::SEPARATOR
21
+ @output << format_colour("\n\nSUMMARY:\n\t", :cyan)
22
+
23
+ build_summary(summary)
24
+ end
25
+
26
+ def dump_pending(notification)
27
+ @output << RSpec::Ci::Prettify::Constants::SEPARATOR
28
+ @output << format_colour("\n\nPENDING:\n\t", :pending)
29
+
30
+ @output << notification.pending_examples.map do |example|
31
+ format_colour(format_example_summary(example), :pending)
32
+ end.join("\n\t")
33
+ end
34
+
35
+ def dump_failures(notification)
36
+ @output << RSpec::Ci::Prettify::Constants::SEPARATOR
37
+ @output << format_colour("\n\nFAILURES:\n\t", :failure)
38
+ @output << failed_examples_output(notification)
39
+ end
40
+
41
+ def example_passed(example)
42
+ # @output << RSpec::Core::Formatters::ConsoleCodes.wrap(".", :success)
43
+ end
44
+
45
+ def example_failed(example)
46
+ # @output << RSpec::Core::Formatters::ConsoleCodes.wrap("F", :failure)
47
+ end
48
+
49
+ def example_pending(example)
50
+ # @output << RSpec::Core::Formatters::ConsoleCodes.wrap("*", :pending)
51
+ end
52
+
53
+ def close(_notification)
54
+ @output << "\n"
55
+ end
56
+
57
+ private
58
+
59
+ def build_summary(summary)
60
+ total_test_count = summary.examples.count
61
+ pending_count = summary.pending_examples.count
62
+ total_tests_ran = total_test_count - pending_count
63
+
64
+ failure_count = summary.failed_examples.count
65
+ pass_count = total_tests_ran - failure_count
66
+
67
+ @output << build_test_suite_duration(summary, total_tests_ran)
68
+ @output << build_pending_summary(pending_count, total_test_count)
69
+
70
+ if pass_count == total_tests_ran
71
+ @output << format_colour("\n All #{total_tests_ran} tests ran passed!!!", :magenta)
72
+ return
73
+ end
74
+
75
+ @output << build_failure_summary(failure_count, total_tests_ran)
76
+ @output << build_pass_summary(pass_count, total_tests_ran)
77
+ end
78
+
79
+ def build_test_suite_duration(summary, test_run_count)
80
+ duration = RSpec::Core::Formatters::Helpers.format_duration(summary.duration)
81
+ duration_text = "\nRan #{test_run_count} tests overall in #{duration}."
82
+
83
+ format_colour(duration_text, :cyan)
84
+ end
85
+
86
+ def build_pending_summary(pending_count, total_test_count)
87
+ 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)
90
+ end
91
+
92
+ def build_failure_summary(failure_count, total_tests_ran)
93
+ 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)
96
+ end
97
+
98
+ def build_pass_summary(pass_count, total_tests_ran)
99
+ pass_percentage = percentage_of_examples(pass_count, total_tests_ran)
100
+
101
+ pass_summary = "\n #{pass_percentage} of tests passed (#{pass_count})"
102
+
103
+ indent(format_colour(pass_summary, :success), 4)
104
+ end
105
+
106
+ def percentage_of_examples(count, total)
107
+ percentage = (count.to_f / total) * 100.0
108
+ "#{percentage.round(2)}%"
109
+ end
110
+
111
+ def failed_examples_output(notification)
112
+ failed_examples_output = notification.failed_examples.map do |example|
113
+ failed_example_output(example)
114
+ end
115
+
116
+ build_examples_output(failed_examples_output)
117
+ end
118
+
119
+ def build_examples_output(output)
120
+ output.join("\n\n\t")
121
+ end
122
+
123
+ def format_colour(str, status)
124
+ RSpec::Core::Formatters::ConsoleCodes.wrap(str, status)
125
+ end
126
+
127
+ def format_example_summary(example)
128
+ full_description = example.full_description
129
+ location = example.location
130
+ "#{full_description} - #{location}"
131
+ end
132
+
133
+ def failed_example_output(example)
134
+ msg = example.execution_result.exception.message
135
+ formatted_err_message = sanitize_msg(msg)
136
+ summary = format_colour(format_example_summary(example), :failure)
137
+
138
+ "#{summary} \n #{formatted_err_message}"
139
+ end
140
+
141
+ def sanitize_msg(msg)
142
+ msg.split("\n").map(&:strip).join("\n#{' ' * 10}")
143
+ end
144
+
145
+ def indent(str, count)
146
+ indent = ' ' * count
147
+ indent + str
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Ci
5
+ module Prettify
6
+ VERSION = '0.1.0'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'prettify/version'
4
+ require_relative 'prettify/formatter'
5
+
6
+ module RSpec
7
+ module Ci
8
+ module Prettify
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-ci-prettify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jjholmes927
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.14.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.14.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description:
56
+ email:
57
+ - jjholmes927@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/rspec/ci/prettify.rb
63
+ - lib/rspec/ci/prettify/constants.rb
64
+ - lib/rspec/ci/prettify/formatter.rb
65
+ - lib/rspec/ci/prettify/version.rb
66
+ homepage: https://github.com/jjholmes927/rspec-ci-prettify
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ allowed_push_host: https://rubygems.org
71
+ homepage_uri: https://github.com/jjholmes927/rspec-ci-prettify
72
+ source_code_uri: https://github.com/jjholmes927/rspec-ci-prettify
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.6.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.2.22
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: rspec formatter that gives a more readable output on CI runs (specifically
92
+ Github actions)
93
+ test_files: []