rspec_trunk_flaky_tests 0.7.2-x86_64-darwin → 0.7.5-x86_64-darwin
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 +4 -4
- data/lib/context_ruby/3.0/context_ruby.bundle +0 -0
- data/lib/context_ruby/3.1/context_ruby.bundle +0 -0
- data/lib/context_ruby/3.2/context_ruby.bundle +0 -0
- data/lib/context_ruby/3.3/context_ruby.bundle +0 -0
- data/lib/context_ruby/3.4/context_ruby.bundle +0 -0
- data/lib/trunk_spec_helper.rb +66 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86574eb1db68bf0f06f4b2e03c072b746a74e2da8cfe324af79ec3e6adc3bd67
|
4
|
+
data.tar.gz: 7e15460fbd3f2ec674df1b646f1ae751bfb86048819ab11f29c9b38d7bdbfdca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451200763b498f417460f84bcc9daf80e8b69f6c996e2b59abc0b1bdcebba780cd395ef19b3966b4092e08cf17c8268ec3ee37d0ff0e04101b558285fb55dc24
|
7
|
+
data.tar.gz: 887b4af52a1814332fd9f2d99771d5d66a2d8ee04dce1898deac9d7fe2896827948b38c6344cd44f8655c41d80c6bb88d21180c20ca4be75c00e8aa5552bc6de
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/trunk_spec_helper.rb
CHANGED
@@ -4,10 +4,47 @@ require 'rspec/core'
|
|
4
4
|
require 'time'
|
5
5
|
require 'context_ruby'
|
6
6
|
|
7
|
+
class String
|
8
|
+
def colorize(color_code)
|
9
|
+
"\e[#{color_code}m#{self}\e[0m"
|
10
|
+
end
|
11
|
+
|
12
|
+
def red
|
13
|
+
colorize(31)
|
14
|
+
end
|
15
|
+
|
16
|
+
def green
|
17
|
+
colorize(32)
|
18
|
+
end
|
19
|
+
|
20
|
+
def yellow
|
21
|
+
colorize(33)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
7
25
|
def escape(str)
|
8
26
|
str.dump[1..-2]
|
9
27
|
end
|
10
28
|
|
29
|
+
def description_generated?(example)
|
30
|
+
auto_generated_exp = /^\s?is expected to eq .*$/
|
31
|
+
full_description = example.full_description
|
32
|
+
parent_description = example.example_group.description
|
33
|
+
checked_description = full_description.sub(parent_description, '')
|
34
|
+
!auto_generated_exp.match(checked_description).nil? || full_description.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_id(example)
|
38
|
+
return "trunk:#{example.id}-#{example.location}" if description_generated?(example)
|
39
|
+
end
|
40
|
+
|
41
|
+
def trunk_disabled
|
42
|
+
ENV['DISABLE_RSPEC_TRUNK_FLAKY_TESTS'] == 'true' || ENV['TRUNK_ORG_URL_SLUG'].nil? || ENV['TRUNK_API_TOKEN'].nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
# we want to cache the test report so we can add to it as we go and reduce the number of API calls
|
46
|
+
$test_report = TestReport.new('rspec', "#{$PROGRAM_NAME} #{ARGV.join(' ')}")
|
47
|
+
|
11
48
|
module RSpec
|
12
49
|
module Core
|
13
50
|
# Example is the class that represents a test case
|
@@ -17,16 +54,25 @@ module RSpec
|
|
17
54
|
# RSpec uses the existance of an exception to determine if the test failed
|
18
55
|
# We need to override this to allow us to capture the exception and then
|
19
56
|
# decide if we want to fail the test or not
|
20
|
-
# trunk-ignore(rubocop/Naming/AccessorMethodName)
|
57
|
+
# trunk-ignore(rubocop/Naming/AccessorMethodName,rubocop/Metrics/MethodLength,rubocop/Metrics/AbcSize)
|
21
58
|
def set_exception(exception)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
59
|
+
return set_exception_core(exception) if trunk_disabled
|
60
|
+
|
61
|
+
id = generate_id(self)
|
62
|
+
name = full_description
|
63
|
+
parent_name = example_group.metadata[:description]
|
64
|
+
parent_name = parent_name.empty? ? 'rspec' : parent_name
|
65
|
+
file = escape(metadata[:file_path])
|
66
|
+
classname = file.sub(%r{\.[^/.]+\Z}, '').gsub('/', '.').gsub(/\A\.+|\.+\Z/, '')
|
67
|
+
puts "Test failed, checking if it can be quarantined: `#{location}`".yellow
|
68
|
+
if $test_report.is_quarantined(id, name, parent_name, classname, file)
|
27
69
|
# monitor the override in the metadata
|
28
70
|
metadata[:quarantined_exception] = exception
|
71
|
+
puts "Test is quarantined, overriding exception: #{exception}".green
|
29
72
|
nil
|
73
|
+
else
|
74
|
+
puts 'Test is not quarantined, continuing'.red
|
75
|
+
set_exception_core(exception)
|
30
76
|
end
|
31
77
|
end
|
32
78
|
|
@@ -45,7 +91,7 @@ module RSpec
|
|
45
91
|
class Trunk
|
46
92
|
def self.setup
|
47
93
|
RSpec.configure do |config|
|
48
|
-
if
|
94
|
+
if trunk_disabled
|
49
95
|
config.around(:each, &:run)
|
50
96
|
else
|
51
97
|
config.around(:each, &:run_with_trunk)
|
@@ -70,10 +116,6 @@ module RSpec
|
|
70
116
|
else
|
71
117
|
@example.metadata[:attempt_number] = 0
|
72
118
|
end
|
73
|
-
|
74
|
-
# add the test to the report
|
75
|
-
# return the report
|
76
|
-
@testreport
|
77
119
|
end
|
78
120
|
end
|
79
121
|
end
|
@@ -82,7 +124,7 @@ end
|
|
82
124
|
# it generates and submits the final test reports
|
83
125
|
class TrunkAnalyticsListener
|
84
126
|
def initialize
|
85
|
-
@testreport =
|
127
|
+
@testreport = $test_report
|
86
128
|
end
|
87
129
|
|
88
130
|
def example_finished(notification)
|
@@ -90,34 +132,18 @@ class TrunkAnalyticsListener
|
|
90
132
|
end
|
91
133
|
|
92
134
|
def close(_notification)
|
93
|
-
@testreport.publish
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
full_description = example.full_description
|
99
|
-
parent_description = example.example_group.description
|
100
|
-
checked_description = full_description.sub(parent_description, '')
|
101
|
-
auto_generated_exp.match(checked_description) != nil
|
102
|
-
end
|
103
|
-
|
104
|
-
def generate_id(example)
|
105
|
-
if description_generated?(example)
|
106
|
-
# trunk-ignore(rubocop/Style/SoleNestedConditional)
|
107
|
-
return "trunk:#{example.id}-#{example.location}" if description_generated?(example)
|
135
|
+
res = @testreport.publish
|
136
|
+
if res
|
137
|
+
puts 'Flaky tests report upload complete'.green
|
138
|
+
else
|
139
|
+
puts 'Failed to publish flaky tests report'.red
|
108
140
|
end
|
109
|
-
nil
|
110
141
|
end
|
111
142
|
|
112
143
|
# trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength,rubocop/Metrics/CyclomaticComplexity)
|
113
144
|
def add_test_case(example)
|
114
|
-
if example.exception
|
115
|
-
|
116
|
-
# failure details is far more robust than the message, but noiser
|
117
|
-
# if example.exception.backtrace
|
118
|
-
# failure_details = example.exception.backtrace.join('\n')
|
119
|
-
# end
|
120
|
-
end
|
145
|
+
failure_message = example.exception.to_s if example.exception
|
146
|
+
failure_message = example.metadata[:quarantined_exception].to_s if example.metadata[:quarantined_exception]
|
121
147
|
# TODO: should we use concatenated string or alias when auto-generated description?
|
122
148
|
name = example.full_description
|
123
149
|
file = escape(example.metadata[:file_path])
|
@@ -129,9 +155,11 @@ class TrunkAnalyticsListener
|
|
129
155
|
|
130
156
|
attempt_number = example.metadata[:attempt_number] || 0
|
131
157
|
status = example.execution_result.status.to_s
|
158
|
+
# set the status to failure, but mark it as quarantined
|
159
|
+
is_quarantined = example.metadata[:quarantined_exception] ? true : false
|
132
160
|
case example.execution_result.status
|
133
161
|
when :passed
|
134
|
-
status = Status.new('success')
|
162
|
+
status = is_quarantined ? Status.new('failure') : Status.new('success')
|
135
163
|
when :failed
|
136
164
|
status = Status.new('failure')
|
137
165
|
when :pending
|
@@ -140,12 +168,12 @@ class TrunkAnalyticsListener
|
|
140
168
|
parent_name = example.example_group.metadata[:description]
|
141
169
|
parent_name = parent_name.empty? ? 'rspec' : parent_name
|
142
170
|
@testreport.add_test(id, name, classname, file, parent_name, line, status, attempt_number,
|
143
|
-
started_at, finished_at, failure_message || '')
|
171
|
+
started_at, finished_at, failure_message || '', is_quarantined)
|
144
172
|
end
|
145
173
|
end
|
146
174
|
|
147
175
|
RSpec.configure do |c|
|
148
|
-
next if
|
176
|
+
next if trunk_disabled
|
149
177
|
|
150
178
|
c.reporter.register_listener TrunkAnalyticsListener.new, :example_finished, :close
|
151
179
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_trunk_flaky_tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Trunk Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|