rspec-ci-prettify 0.2.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: cf3101b2b7072996c975de110df7bac584d6205895ab9bf552bcf41fa35617b8
4
- data.tar.gz: 1845bf2494e6b29d36dee4c2c27141e54e3aa832b979717b4fcff2a5f78dc54d
3
+ metadata.gz: f4814566aeb1130a8ca2d63035a0664b8120753d608c280270f3e2369141033d
4
+ data.tar.gz: f2ee21c3127d7e5fc789994ee2efc75baafc0848ee81fda995f57c57e0ce96f1
5
5
  SHA512:
6
- metadata.gz: 9614286b2c32940116ddbfb04d60945c334f3ee03deb77b099480ab41814748cdd1b16d023654eee04faf14fb97fb4b0494e04bc86559671a5723515ac4bd84d
7
- data.tar.gz: 26fca45f6d8e042fb3907bdb098b977128079d56e2eed9e821588c4f375532b1b3ff0cc50df4bdd71c1630eaa516fdf426371f61eda1ef20af6e0c93e94d23cd
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
@@ -20,7 +21,7 @@ module RSpec
20
21
  @output << "\n\n"
21
22
  @output << RSpec::Core::Formatters::ConsoleCodes.wrap(RSpec::Ci::Prettify::Constants::SEPARATOR, :bold_white)
22
23
  @output << "\n\n"
23
- @output << RSpec::Core::Formatters::ConsoleCodes.wrap("SUMMARY:", :cyan)
24
+ @output << RSpec::Core::Formatters::ConsoleCodes.wrap('SUMMARY:', :cyan)
24
25
 
25
26
  build_summary(summary)
26
27
  end
@@ -29,7 +30,7 @@ module RSpec
29
30
  @output << "\n\n"
30
31
  @output << RSpec::Core::Formatters::ConsoleCodes.wrap(RSpec::Ci::Prettify::Constants::SEPARATOR, :bold_white)
31
32
  @output << "\n\n"
32
- @output << RSpec::Core::Formatters::ConsoleCodes.wrap("PENDING:", :pending)
33
+ @output << RSpec::Core::Formatters::ConsoleCodes.wrap('PENDING:', :pending)
33
34
  @output << "\n\n\t"
34
35
 
35
36
  @output << notification.pending_examples.map do |example|
@@ -41,20 +42,19 @@ module RSpec
41
42
  @output << "\n\n"
42
43
  @output << RSpec::Core::Formatters::ConsoleCodes.wrap(RSpec::Ci::Prettify::Constants::SEPARATOR, :bold_white)
43
44
  @output << "\n\n"
44
- @output << RSpec::Core::Formatters::ConsoleCodes.wrap("FAILURES:", :failure)
45
+ @output << RSpec::Core::Formatters::ConsoleCodes.wrap('FAILURES:', :failure)
45
46
  @output << "\n\n\t"
46
47
  @output << failed_examples_output(notification)
47
48
  end
48
49
 
49
- def example_passed(example)
50
-
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}"
51
53
  end
52
54
 
53
- def example_failed(example)
54
- end
55
+ def example_passed(_example); end
55
56
 
56
- def example_pending(example)
57
- end
57
+ def example_pending(_example); end
58
58
 
59
59
  def close(_notification)
60
60
  @output << "\n"
@@ -76,7 +76,8 @@ module RSpec
76
76
 
77
77
  if pass_count == total_tests_ran
78
78
  @output << "\n"
79
- @output << RSpec::Core::Formatters::ConsoleCodes.wrap("All #{total_tests_ran} tests ran passed!!!", :magenta)
79
+ @output << RSpec::Core::Formatters::ConsoleCodes.wrap("All #{total_tests_ran} tests ran passed!!!",
80
+ :magenta)
80
81
  return
81
82
  end
82
83
  @output << "\n"
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Ci
5
5
  module Prettify
6
- VERSION = '0.2.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.2.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-05 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