trunk_analytics 0.0.2
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 +7 -0
- data/lib/context_ruby/context_ruby.so +0 -0
- data/lib/context_ruby.rb +3 -0
- data/lib/trunk_analytics/trunk_spec_helper.rb +147 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb653889166b3a11b36ac6aac5f05647c2ae2afa07d2f508393843580813e021
|
4
|
+
data.tar.gz: b5a011b868058342e28aa501360aac88fc116c562ee59ba7615f5a4613cd272f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dfea8feadaca40dfec3aeb0491746a244977c587d10267f1e35e51def892969b3c0166e83d77e7d188cac21bec690cb87275c9246afb7414d27849db095344c
|
7
|
+
data.tar.gz: 5a1fe76e0c46398ff1309b616df2dd3ad7561b5d5a4fc4b36d958bf55b839758a3768dd7bccd9a1968c181495dd72de40cfe1a128359c24c929982598cfce9ff
|
Binary file
|
data/lib/context_ruby.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec/core'
|
4
|
+
require 'time'
|
5
|
+
require 'context_ruby/context_ruby'
|
6
|
+
|
7
|
+
def escape(str)
|
8
|
+
str.dump[1..-2]
|
9
|
+
end
|
10
|
+
|
11
|
+
module RSpec
|
12
|
+
module Core
|
13
|
+
# Example is the class that represents a test case
|
14
|
+
class Example
|
15
|
+
# keep the original method around so we can call it
|
16
|
+
alias set_exception_core set_exception
|
17
|
+
# RSpec uses the existance of an exception to determine if the test failed
|
18
|
+
# We need to override this to allow us to capture the exception and then
|
19
|
+
# decide if we want to fail the test or not
|
20
|
+
# trunk-ignore(rubocop/Naming/AccessorMethodName)
|
21
|
+
def set_exception(exception)
|
22
|
+
# TODO: this is where we'll need to override the result once the logic is ready
|
23
|
+
# trunk-ignore(rubocop/Lint/LiteralAsCondition)
|
24
|
+
if true
|
25
|
+
set_exception_core(exception)
|
26
|
+
else
|
27
|
+
# monitor the override in the metadata
|
28
|
+
metadata[:quarantined_exception] = exception
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Procsy is a class that is used to wrap execution of the Example class
|
34
|
+
class Procsy
|
35
|
+
def run_with_trunk
|
36
|
+
RSpec::Trunk.new(self).run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module RSpec
|
44
|
+
# Trunk is a class that is used to monitor the execution of the Example class
|
45
|
+
class Trunk
|
46
|
+
def self.setup
|
47
|
+
RSpec.configure do |config|
|
48
|
+
config.around(:each, &:run_with_trunk)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(example)
|
53
|
+
@example = example
|
54
|
+
end
|
55
|
+
|
56
|
+
def current_example
|
57
|
+
@current_example ||= RSpec.current_example
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
# run the test
|
62
|
+
@example.run
|
63
|
+
# monitor attempts in the metadata
|
64
|
+
if @example.metadata[:attempt_number]
|
65
|
+
@example.metadata[:attempt_number] += 1
|
66
|
+
else
|
67
|
+
@example.metadata[:attempt_number] = 0
|
68
|
+
end
|
69
|
+
|
70
|
+
# add the test to the report
|
71
|
+
# return the report
|
72
|
+
@testreport
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# TrunkAnalyticsListener is a class that is used to listen to the execution of the Example class
|
78
|
+
# it generates and submits the final test reports
|
79
|
+
class TrunkAnalyticsListener
|
80
|
+
def initialize
|
81
|
+
@testreport = TestReport.new('rspec')
|
82
|
+
end
|
83
|
+
|
84
|
+
def example_finished(notification)
|
85
|
+
add_test_case(notification.example)
|
86
|
+
end
|
87
|
+
|
88
|
+
def close(_notification)
|
89
|
+
@testreport.publish('..')
|
90
|
+
end
|
91
|
+
|
92
|
+
def description_generated?(example)
|
93
|
+
auto_generated_exp = /^\s?is expected to eq .*$/
|
94
|
+
full_description = example.full_description
|
95
|
+
parent_description = example.example_group.description
|
96
|
+
checked_description = full_description.sub(parent_description, '')
|
97
|
+
auto_generated_exp.match(checked_description) != nil
|
98
|
+
end
|
99
|
+
|
100
|
+
def generate_id(example)
|
101
|
+
if description_generated?(example)
|
102
|
+
# trunk-ignore(rubocop/Style/SoleNestedConditional)
|
103
|
+
return "#{example.id}-#{example.location}" if description_generated?(example)
|
104
|
+
end
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
108
|
+
# trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength,rubocop/Metrics/CyclomaticComplexity)
|
109
|
+
def add_test_case(example)
|
110
|
+
if example.exception
|
111
|
+
failure_message = example.exception.message
|
112
|
+
# failure details is far more robust than the message, but noiser
|
113
|
+
# if example.exception.backtrace
|
114
|
+
# failure_details = example.exception.backtrace.join('\n')
|
115
|
+
# end
|
116
|
+
end
|
117
|
+
# TODO: should we use concatenated string or alias when auto-generated description?
|
118
|
+
name = example.full_description
|
119
|
+
file = escape(example.metadata[:file_path])
|
120
|
+
classname = file.sub(%r{\.[^/.]+\Z}, '').gsub('/', '.').gsub(/\A\.+|\.+\Z/, '')
|
121
|
+
line = example.metadata[:line_number]
|
122
|
+
started_at = example.execution_result.started_at.to_i
|
123
|
+
finished_at = example.execution_result.finished_at.to_i
|
124
|
+
id = generate_id(example)
|
125
|
+
|
126
|
+
attempt_number = example.metadata[:attempt_number] || 0
|
127
|
+
status = example.execution_result.status.to_s
|
128
|
+
case example.execution_result.status
|
129
|
+
when :passed
|
130
|
+
status = Status.new('success')
|
131
|
+
when :failed
|
132
|
+
status = Status.new('failure')
|
133
|
+
when :pending
|
134
|
+
status = Status.new('skipped')
|
135
|
+
end
|
136
|
+
parent_name = example.example_group.metadata[:description]
|
137
|
+
parent_name = parent_name.empty? ? 'rspec' : parent_name
|
138
|
+
@testreport.add_test(id, name, classname, file, parent_name, line, status, attempt_number,
|
139
|
+
started_at, finished_at, failure_message || '')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
RSpec.configure do |c|
|
144
|
+
c.reporter.register_listener TrunkAnalyticsListener.new, :example_finished, :close
|
145
|
+
end
|
146
|
+
|
147
|
+
RSpec::Trunk.setup
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trunk_analytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trunk Technologies, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: trunk analytics helper gem
|
14
|
+
email: support@trunk.io
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/context_ruby.rb
|
20
|
+
- lib/context_ruby/context_ruby.so
|
21
|
+
- lib/trunk_analytics/trunk_spec_helper.rb
|
22
|
+
homepage: https://trunk.io
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.5.6
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: trunk analytics helper gem
|
45
|
+
test_files: []
|