knapsack_pro 8.3.0 → 8.3.1

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: 154cc1aaba977644e5f9dd5298e594ba4e6bbc4a67ec1edf1caac2aaf3d21ebb
4
- data.tar.gz: 11a7acd42b97cd0e2d0075733e0a34ebcc5677f1cbd2e5342cccb2745405cadd
3
+ metadata.gz: 8c6268ccfd0e07224b6fbae963baa01c2f6344b924b7b3b1097a42474c57e3b7
4
+ data.tar.gz: 909d3632bcede5ecd49e075edc62b4c8a602b31cd1e059c99097a92bd6b21c75
5
5
  SHA512:
6
- metadata.gz: 733e3fc942afe5ba74bc1b689ac9255bba46e28ddfdd60a826a0946f68a9c208d139786c2ff32319885adbe1c1a0e0696d9f63c5dc1a916b6b5a4072af3e9de8
7
- data.tar.gz: 5769bf6874b3b93a1349268688d0304015da91072d9661852b034e937628f1be51d17a4e96a9124713fc6a730f953257989ba4613c6d5246de6ac8ec332c21e7
6
+ metadata.gz: 94cd957dcb04b6157e0aa6902cf6576e67857099b7c4db232742d7a420d08cc588e0dead4bb1d9ec7103024de0b2fe9edbeddacc0575d00533e530cd4c125465
7
+ data.tar.gz: cf30d4fddcab85d7ce32b589ef624bf08e78eb7d2ad236410c0d162538f3eee457311a7ff9a3ac08fb25440490574d707bf171d252e8dda4b9457138feced4b5
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
2
 
3
- ### UNRELEASED
3
+ ### UNRELEASED (patch)
4
+
5
+ ### 8.3.1
6
+
7
+ * Fix RSpec TimeTracker to properly track `before(:all)/after(:all)`.
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/303
10
+
11
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v8.3.0...v8.3.1
12
+
4
13
 
5
14
  ### 8.3.0
6
15
 
@@ -19,7 +19,7 @@ module KnapsackPro
19
19
  @output = StringIO.new
20
20
  @time_each = nil
21
21
  @time_all = nil
22
- @before_all = 0.0
22
+ @time_all_by_group_id_path = Hash.new(0)
23
23
  @group = {}
24
24
  @paths = {}
25
25
  @suite_started = now
@@ -38,12 +38,12 @@ module KnapsackPro
38
38
  end
39
39
 
40
40
  def example_group_started(notification)
41
- return unless top_level_group?(notification.group)
41
+ record_time_all(notification.group.parent_groups[1], @time_all_by_group_id_path, @time_all)
42
42
  @time_all = now
43
43
  end
44
44
 
45
- def example_started(_notification)
46
- @before_all = now - @time_all if @before_all == 0.0
45
+ def example_started(notification)
46
+ record_time_all(notification.example.example_group, @time_all_by_group_id_path, @time_all)
47
47
  @time_each = now
48
48
  end
49
49
 
@@ -53,11 +53,12 @@ module KnapsackPro
53
53
  end
54
54
 
55
55
  def example_group_finished(notification)
56
+ record_time_all(notification.group, @time_all_by_group_id_path, @time_all)
57
+ @time_all = now
56
58
  return unless top_level_group?(notification.group)
57
59
 
58
- after_all = @time_all.nil? ? 0.0 : now - @time_all
59
- add_hooks_time(@group, @before_all, after_all)
60
- @before_all = 0.0
60
+ add_hooks_time(@group, @time_all_by_group_id_path)
61
+ @time_all_by_group_id_path = Hash.new(0)
61
62
  @paths = merge(@paths, @group)
62
63
  @group = {}
63
64
  end
@@ -104,10 +105,17 @@ module KnapsackPro
104
105
  group.metadata[:parent_example_group].nil?
105
106
  end
106
107
 
107
- def add_hooks_time(group, before_all, after_all)
108
+ def add_hooks_time(group, time_all_by_group_id_path)
108
109
  group.each do |_, example|
109
110
  next if example[:time_execution] == 0.0
110
- example[:time_execution] += before_all + after_all
111
+
112
+ example[:time_execution] += time_all_by_group_id_path.sum do |group_id_path, time|
113
+ # :path is a file path (a_spec.rb), sum any before/after(:all) in the file
114
+ next time if group_id_path.start_with?(example[:path])
115
+ # :path is an id path (a_spec.rb[1:1]), sum any before/after(:all) above it
116
+ next time if example[:path].start_with?(group_id_path[0..-2])
117
+ 0
118
+ end
111
119
  end
112
120
  end
113
121
 
@@ -123,6 +131,13 @@ module KnapsackPro
123
131
  end
124
132
  end
125
133
 
134
+ def record_time_all(group, time_all_by_group_id_path, time_all)
135
+ return unless group # above top level group
136
+
137
+ group_id_path = KnapsackPro::TestFileCleaner.clean(group.id)
138
+ time_all_by_group_id_path[group_id_path] += now - time_all
139
+ end
140
+
126
141
  def path_for(example)
127
142
  file_path = file_path_for(example)
128
143
  return nil if file_path == ""
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KnapsackPro
4
- VERSION = '8.3.0'
4
+ VERSION = '8.3.1'
5
5
  end
@@ -220,6 +220,63 @@ class TestTimeTracker
220
220
  end
221
221
  end
222
222
 
223
+ def test_nested_hooks
224
+ KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
225
+ false
226
+ end
227
+
228
+ spec = <<~SPEC
229
+ describe "KnapsackPro::Formatters::TimeTracker" do
230
+ before(:all) do
231
+ sleep 0.1
232
+ end
233
+
234
+ after(:all) do
235
+ sleep 0.1
236
+ end
237
+
238
+ it do
239
+ expect(1).to eq 1
240
+ end
241
+
242
+ describe do
243
+ before(:all) do
244
+ sleep 0.1
245
+ end
246
+
247
+ after(:all) do
248
+ sleep 0.1
249
+ end
250
+
251
+ it do
252
+ expect(1).to eq 1
253
+ end
254
+ end
255
+
256
+ describe do
257
+ before(:all) do
258
+ sleep 0.1
259
+ end
260
+
261
+ after(:all) do
262
+ sleep 0.1
263
+ end
264
+
265
+ it do
266
+ expect(1).to eq 1
267
+ end
268
+ end
269
+ end
270
+ SPEC
271
+
272
+ run_specs(spec) do |spec_paths, times|
273
+ raise unless times.size == 1
274
+ raise unless times[0]["path"] == spec_paths.first
275
+ raise unless times[0]["time_execution"] > 0.60
276
+ raise unless times[0]["time_execution"] < 0.65
277
+ end
278
+ end
279
+
223
280
  def test_hooks_with_rspec_split_by_test_example
224
281
  KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
225
282
  true
@@ -263,6 +320,68 @@ class TestTimeTracker
263
320
  end
264
321
  end
265
322
 
323
+ def test_nested_hooks_with_rspec_split_by_test_example
324
+ KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
325
+ true
326
+ end
327
+
328
+ spec = <<~SPEC
329
+ describe "KnapsackPro::Formatters::TimeTracker" do
330
+ before(:all) do
331
+ sleep 0.1
332
+ end
333
+
334
+ after(:all) do
335
+ sleep 0.1
336
+ end
337
+
338
+ it do
339
+ expect(1).to eq 1
340
+ end
341
+
342
+ describe do
343
+ before(:all) do
344
+ sleep 0.1
345
+ end
346
+
347
+ after(:all) do
348
+ sleep 0.1
349
+ end
350
+
351
+ it do
352
+ expect(1).to eq 1
353
+ end
354
+ end
355
+
356
+ describe do
357
+ before(:all) do
358
+ sleep 0.1
359
+ end
360
+
361
+ after(:all) do
362
+ sleep 0.1
363
+ end
364
+
365
+ it do
366
+ expect(1).to eq 1
367
+ end
368
+ end
369
+ end
370
+ SPEC
371
+
372
+ run_specs(spec) do |spec_paths, times|
373
+ raise unless times.size == 3
374
+ spec_path = spec_paths.first
375
+ raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] > 0.20
376
+ raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] < 0.25
377
+ raise unless times.find { |time| time["path"] == "#{spec_path}[1:2:1]" }["time_execution"] > 0.40
378
+ raise unless times.find { |time| time["path"] == "#{spec_path}[1:2:1]" }["time_execution"] < 0.45
379
+ raise unless times.find { |time| time["path"] == "#{spec_path}[1:3:1]" }["time_execution"] > 0.40
380
+ raise unless times.find { |time| time["path"] == "#{spec_path}[1:3:1]" }["time_execution"] < 0.45
381
+ end
382
+ end
383
+
384
+
266
385
  def test_unknown_path
267
386
  KnapsackPro::Formatters::TimeTracker.class_eval do
268
387
  alias_method :original_file_path_for, :file_path_for
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.3.0
4
+ version: 8.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -428,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
428
428
  - !ruby/object:Gem::Version
429
429
  version: '0'
430
430
  requirements: []
431
- rubygems_version: 3.6.2
431
+ rubygems_version: 3.6.7
432
432
  specification_version: 4
433
433
  summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel
434
434
  job finish work at a similar time.