rspec-buildkite-analytics 0.5.0 → 0.6.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: a9fc407bacf4405e3d3e2ee4043a9c71f20d75a363d3ba33948b37403a6e8de4
4
- data.tar.gz: 67f8b42a6ac98518d784eea442fb9efc5a1c8dd5ca0037cc5ce5664b180b75ec
3
+ metadata.gz: 1ca7801b3e7bc48f52a372df29c553c9e2dad5bffdab1bf8dff0b20f0173b987
4
+ data.tar.gz: 22d6197b37f465afa1a2a309ba4f3780bafef928d626768a5d4d3fa6d214a809
5
5
  SHA512:
6
- metadata.gz: 6c368891ad4401ac9112a618953686c79b2e69bd33824be1477e3416f99f03233210d80ad3d3a1eccd9b251f595f2b879fd79de0eb1d80193544a6812e8ac0b9
7
- data.tar.gz: 2cf265c336146324d21b06d8c3ec4827848dcb0580ac626d49cd82eaab10ef5101f9398bdad10c118c5dfd42276ed2e70441f8c42b6881a8d68bf6a05da73485
6
+ metadata.gz: '0380c462ae87c2dd2dbb830bbcdc93bef621b74f2f516c465b37e633679e9e0c887fe8557356aaf85abd8e7fe179110b86aabceb339057cd89e37c00afcac107'
7
+ data.tar.gz: 9b6810ff8529454f543b70f521b34906223e2ee02ad1f0d4cd261d4bfe6e2c4ed21eb76c8eddfb08818c9c8a07d07cb62c3c206c958c48743a47c1dfde83f9b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-buildkite-analytics (0.5.0)
4
+ rspec-buildkite-analytics (0.6.0)
5
5
  activesupport (>= 5.2, <= 7.0)
6
6
  rspec-core (~> 3.10)
7
7
  rspec-expectations (~> 3.10)
@@ -18,6 +18,7 @@ module RSpec::Buildkite::Analytics
18
18
 
19
19
  if trace
20
20
  trace.example = example
21
+ trace.failure_reason, trace.failure_expanded = failure_info(notification) if example.execution_result.status == :failed
21
22
  RSpec::Buildkite::Analytics.session&.write_result(trace)
22
23
  end
23
24
  end
@@ -45,9 +46,54 @@ module RSpec::Buildkite::Analytics
45
46
  end
46
47
  end
47
48
  end
48
-
49
+
49
50
  alias_method :example_passed, :handle_example
50
51
  alias_method :example_failed, :handle_example
51
52
  alias_method :example_pending, :handle_example
53
+
54
+ private
55
+
56
+ def failure_info(notification)
57
+ failure_expanded = []
58
+
59
+ if notification.exception.class == RSpec::Expectations::MultipleExpectationsNotMetError
60
+ failure_reason = notification.exception.summary
61
+ notification.exception.all_exceptions.each do |exception|
62
+ # an example with multiple failures doesn't give us a
63
+ # separate message lines and backtrace object to send, so
64
+ # I've reached into RSpec internals and duplicated the
65
+ # construction of these
66
+ message_lines = RSpec::Core::Formatters::ExceptionPresenter.new(exception, notification.example).colorized_message_lines
67
+
68
+ failure_expanded << {
69
+ expanded: format_message_lines(message_lines),
70
+ backtrace: RSpec.configuration.backtrace_formatter.format_backtrace(exception.backtrace)
71
+ }
72
+ end
73
+ else
74
+ failure_reason = strip_diff_colors(notification.colorized_message_lines[0])
75
+
76
+ # the second line is always whitespace padding
77
+ message_lines = notification.colorized_message_lines[2..]
78
+
79
+ failure_expanded << {
80
+ expanded: format_message_lines(message_lines),
81
+ backtrace: notification.formatted_backtrace
82
+ }
83
+ end
84
+
85
+ return failure_reason, failure_expanded
86
+ end
87
+
88
+ def format_message_lines(message_lines)
89
+ message_lines.map! { |l| strip_diff_colors(l) }
90
+ # the last line is sometimes blank, depending on the error reported
91
+ message_lines.pop if message_lines.last.blank?
92
+ message_lines
93
+ end
94
+
95
+ def strip_diff_colors(string)
96
+ string.gsub(/\e\[([;\d]+)?m/, '')
97
+ end
52
98
  end
53
99
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/hash/indifferent_access"
4
+
3
5
  module RSpec::Buildkite::Analytics
4
6
  class Tracer
5
7
  class Span
@@ -22,22 +22,15 @@ require "securerandom"
22
22
  module RSpec::Buildkite::Analytics
23
23
  class Uploader
24
24
  class Trace
25
- attr_accessor :example
25
+ attr_accessor :example, :failure_reason, :failure_expanded
26
26
  attr_reader :id, :history
27
27
 
28
28
  def initialize(example, history)
29
29
  @id = SecureRandom.uuid
30
30
  @example = example
31
31
  @history = history
32
- end
33
-
34
- def failure_message
35
- case example.exception
36
- when RSpec::Expectations::ExpectationNotMetError
37
- example.exception.message
38
- when Exception
39
- "#{example.exception.class}: #{example.exception.message}"
40
- end
32
+ @failure_reason = nil
33
+ @failure_expanded = []
41
34
  end
42
35
 
43
36
  def result_state
@@ -57,9 +50,10 @@ module RSpec::Buildkite::Analytics
57
50
  location: example.location,
58
51
  file_name: generate_file_name(example),
59
52
  result: result_state,
60
- failure: failure_message,
53
+ failure_reason: failure_reason,
54
+ failure_expanded: failure_expanded,
61
55
  history: history,
62
- }.with_indifferent_access
56
+ }.with_indifferent_access.compact
63
57
  end
64
58
 
65
59
  private
@@ -121,7 +115,8 @@ module RSpec::Buildkite::Analytics
121
115
  "Content-Type" => "application/json",
122
116
  })
123
117
  contact.body = {
124
- run_env: CI.env
118
+ run_env: CI.env,
119
+ format: "websocket"
125
120
  }.to_json
126
121
 
127
122
  response = begin
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Buildkite
5
5
  module Analytics
6
- VERSION = "0.5.0"
6
+ VERSION = "0.6.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-buildkite-analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport