rspec_trunk_flaky_tests 0.16.2 → 0.16.3
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/trunk_spec_helper.rb +46 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0feac8d56ad33b4a791829c4a5187101fc01f61cc94361dae76bd0e09cfdcd85
|
|
4
|
+
data.tar.gz: b3f3febcc6d003a9a0674c9264f4435ace0230d7e73c84899c23e2dad7c6c3bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 802d0b7be6130964c4d2d59cf4dfb1d2251f7b7f9c1cc307445e1cdc591a1c5ba7597cb1a83a8ed2f650980ae89e29623f8c880c70544d1e41b3c744a426ef74
|
|
7
|
+
data.tar.gz: 680aad00ebdbcb6394b8efb0df1c2a74241b01695bc82587bcfb1d04dfa30f3ecbd78f61457add9b71422525b2797004c5515005c920b4ba75d44a63166a6e7c
|
data/lib/trunk_spec_helper.rb
CHANGED
|
@@ -45,6 +45,15 @@ module RSpec
|
|
|
45
45
|
module Trunk
|
|
46
46
|
ANSI_ESCAPE_PATTERN = %r{(?:\e[@-Z\\-_]|\e\[[0-?]*[ -/]*[@-~])}
|
|
47
47
|
|
|
48
|
+
CORE_METHODS = {
|
|
49
|
+
name: [Module.instance_method(:name), String],
|
|
50
|
+
class: [Kernel.instance_method(:class), Module]
|
|
51
|
+
}.freeze
|
|
52
|
+
CLASS_SUPERCLASS = Class.instance_method(:superclass)
|
|
53
|
+
KERNEL_IS_A = Kernel.instance_method(:is_a?)
|
|
54
|
+
MODULE_TO_S = Module.instance_method(:to_s)
|
|
55
|
+
MEMORY_ADDRESS = /:0x\h+>/
|
|
56
|
+
|
|
48
57
|
# Knapsack example detector instantiates all test cases in order to determine how to shard them
|
|
49
58
|
# These instantiations should not generate test bundles, so we
|
|
50
59
|
# disable the gem when running under knapsack_pro:rspec_test_example_detector
|
|
@@ -180,21 +189,51 @@ module RSpec
|
|
|
180
189
|
end
|
|
181
190
|
|
|
182
191
|
def description_arg(arg)
|
|
183
|
-
if
|
|
184
|
-
arg
|
|
192
|
+
if core_is_a?(arg, Module)
|
|
193
|
+
module_description(arg, arg.to_s)
|
|
185
194
|
elsif default_to_s?(arg)
|
|
186
|
-
|
|
195
|
+
klass = core_call(arg, :class)
|
|
196
|
+
"#<#{module_description(klass, MODULE_TO_S.bind_call(klass))}>"
|
|
187
197
|
else
|
|
188
198
|
arg.to_s
|
|
189
199
|
end
|
|
190
200
|
end
|
|
191
201
|
|
|
192
202
|
def anonymous_module_name(mod)
|
|
193
|
-
return '#<Module>' unless
|
|
203
|
+
return '#<Module>' unless core_is_a?(mod, Class)
|
|
204
|
+
|
|
205
|
+
superclass = CLASS_SUPERCLASS.bind_call(mod)
|
|
206
|
+
superclass = CLASS_SUPERCLASS.bind_call(superclass) while superclass && module_name(superclass).nil?
|
|
207
|
+
superclass ? "#<Class < #{module_name(superclass)}>" : '#<Class>'
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# `described` is the module's #to_s, which is RSpec's (and so 0.16.1's) name for it,
|
|
211
|
+
# kept unless it has an address in it.
|
|
212
|
+
def module_description(mod, described)
|
|
213
|
+
return described unless MEMORY_ADDRESS.match?(described)
|
|
214
|
+
|
|
215
|
+
name = module_name(mod)
|
|
216
|
+
name.nil? || name.empty? ? anonymous_module_name(mod) : name
|
|
217
|
+
end
|
|
194
218
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
219
|
+
def module_name(mod)
|
|
220
|
+
core_call(mod, :name)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# The arg's own method when it works as core's does, else core's: a class may define
|
|
224
|
+
# .name for something else (private, or taking arguments).
|
|
225
|
+
def core_call(obj, method_name)
|
|
226
|
+
core, type = CORE_METHODS.fetch(method_name)
|
|
227
|
+
value = obj.public_send(method_name)
|
|
228
|
+
value.is_a?(type) ? value : core.bind_call(obj)
|
|
229
|
+
rescue StandardError, NotImplementedError
|
|
230
|
+
core.bind_call(obj)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def core_is_a?(obj, type)
|
|
234
|
+
KERNEL_IS_A.bind_call(obj, type)
|
|
235
|
+
rescue TypeError # a BasicObject
|
|
236
|
+
false
|
|
198
237
|
end
|
|
199
238
|
|
|
200
239
|
# Kernel's method, so an object whose own #method means something else
|