knapsack_pro 2.15.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a97f9fbc29f0a109fbbf35b6a544f2ad86208feb697b7ff81f8458b679843c91
4
- data.tar.gz: 434871e67293512331dfe99ed7915eb0f96ae27d2a7b3a1023e8752c752455ac
3
+ metadata.gz: 534699a91609a71a2621b9625a3ff555a58bf385728be90adce4cfe6d6b771dd
4
+ data.tar.gz: 913fc4a85433a50f3639bdc087995f9dc5e482b33d7768cfdb84c0f767326c2c
5
5
  SHA512:
6
- metadata.gz: 3d5be26f0d227707d789b5d7243f3617ea6f839154725b555f0ada89b6600aef0b18aaa2532d018344c797a1f79465e27d3caadebb955d1ca00684b08f1be4ea
7
- data.tar.gz: ddb85043aad801bbb9f47f51c36bace0c34b73f958968e821c7b2e8845cc0a302ef05d9e55033d260a86817d4a99d924084f8c29c86b87ce2c2a75fd96fef4af
6
+ metadata.gz: da5e5ef1c262d97b6214eddff32c8aa2031fe122ad1597a1cf4bd2a939fe82f9fd6b0c7287861f5373521f731318a0e856a331220ae0076eef9cdf8323ab0548
7
+ data.tar.gz: 2e058c2c3b82c9c97481ab84873c652fb3ab4844521c4746efeaca2dccca8b265b58ba427d44af56b130769bf56c6cbacd84b516b1e6b44d099a8a33b2ef340b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ### 2.16.0
4
+
5
+ * Improve test time execution tracking for RSpec
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/145
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.15.0...v2.16.0
10
+
3
11
  ### 2.15.0
4
12
 
5
13
  * Do not allow to use the RSpec tag option together with the RSpec split by test examples feature
data/README.md CHANGED
@@ -793,43 +793,7 @@ $ KNAPSACK_PRO_SALT=xxx bundle exec rake knapsack_pro:encrypted_branch_names[not
793
793
 
794
794
  If you are using circleci.com you can omit `KNAPSACK_PRO_CI_NODE_TOTAL` and `KNAPSACK_PRO_CI_NODE_INDEX`. Knapsack Pro will use `CIRCLE_NODE_TOTAL` and `CIRCLE_NODE_INDEX` provided by CircleCI.
795
795
 
796
- Here is an example for test configuration in your `circleci.yml` file.
797
-
798
- ```yaml
799
- # CircleCI 1.0
800
-
801
- machine:
802
- environment:
803
- # Tokens should be set in CircleCI settings to avoid expose tokens in build logs
804
- # KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: rspec-token
805
- # KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER: cucumber-token
806
- # KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: minitest-token
807
- # KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT: test-unit-token
808
- # KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH: spinach-token
809
- test:
810
- override:
811
- # Step for RSpec
812
- - bundle exec rake knapsack_pro:rspec:
813
- parallel: true # Caution: there are 8 spaces indentation!
814
-
815
- # Step for Cucumber
816
- - bundle exec rake knapsack_pro:cucumber:
817
- parallel: true # Caution: there are 8 spaces indentation!
818
-
819
- # Step for Minitest
820
- - bundle exec rake knapsack_pro:minitest:
821
- parallel: true # Caution: there are 8 spaces indentation!
822
-
823
- # Step for test-unit
824
- - bundle exec rake knapsack_pro:test_unit:
825
- parallel: true # Caution: there are 8 spaces indentation!
826
-
827
- # Step for Spinach
828
- - bundle exec rake knapsack_pro:spinach:
829
- parallel: true # Caution: there are 8 spaces indentation!
830
- ```
831
-
832
- Here is another example for CircleCI 2.0 platform.
796
+ Here is an example for test configuration in your `.circleci/config.yml` file.
833
797
 
834
798
  ```yaml
835
799
  # CircleCI 2.0
@@ -866,7 +830,7 @@ Please remember to add additional containers for your project in CircleCI settin
866
830
 
867
831
  ##### CircleCI and knapsack_pro Queue Mode
868
832
 
869
- If you use knapsack_pro Queue Mode with CircleCI you may want to [collect metadata](https://circleci.com/docs/1.0/test-metadata/#metadata-collection-in-custom-test-steps) like junit xml report about your RSpec test suite.
833
+ If you use knapsack_pro Queue Mode with CircleCI you may want to [collect metadata](https://circleci.com/docs/2.0/collect-test-data/#metadata-collection-in-custom-test-steps) like junit xml report about your RSpec test suite.
870
834
 
871
835
  Here you can read how to configure [junit formatter](https://knapsackpro.com/faq/question/how-to-use-junit-formatter#how-to-use-junit-formatter-with-knapsack_pro-queue-mode). Step for CircleCI is to copy the xml report to `$CIRCLE_TEST_REPORTS` directory. Below is full config for your `spec_helper.rb`:
872
836
 
@@ -913,6 +877,8 @@ Ensure you have in CircleCI config yml
913
877
  destination: test-results
914
878
  ```
915
879
 
880
+ You can find a complete CircleCI YML config example in [the article](https://docs.knapsackpro.com/2021/rspec-testing-parallel-jobs-with-circleci-and-junit-xml-report).
881
+
916
882
  #### Info for Travis users
917
883
 
918
884
  You can parallelize your builds across virtual machines with [travis matrix feature](http://docs.travis-ci.com/user/speeding-up-the-build/#parallelizing-your-builds-across-virtual-machines). Edit `.travis.yml`
@@ -26,6 +26,10 @@ module KnapsackPro
26
26
  end
27
27
 
28
28
  config.around(:each) do |example|
29
+ # stop timer to update time for a previously run test example
30
+ # this way we count time spend in runtime for the previous test example after around(:each) is already done
31
+ KnapsackPro.tracker.stop_timer
32
+
29
33
  current_example_group =
30
34
  if ::RSpec.respond_to?(:current_example)
31
35
  ::RSpec.current_example.metadata[:example_group]
@@ -46,6 +50,8 @@ module KnapsackPro
46
50
  end
47
51
 
48
52
  config.append_after(:context) do
53
+ # after(:context) hook is run one time only, after all of the examples in a group
54
+ # stop timer to count time for the very last executed test example
49
55
  KnapsackPro.tracker.stop_timer
50
56
  end
51
57
 
@@ -19,23 +19,28 @@ module KnapsackPro
19
19
  end
20
20
 
21
21
  def start_timer
22
+ @start_time ||= now_without_mock_time.to_f
23
+ end
24
+
25
+ def reset_timer
22
26
  @start_time = now_without_mock_time.to_f
23
27
  end
24
28
 
25
29
  def stop_timer
26
30
  execution_time = @start_time ? now_without_mock_time.to_f - @start_time : 0.0
27
31
 
28
- if current_test_path
32
+ if @current_test_path
29
33
  update_global_time(execution_time)
30
34
  update_test_file_time(execution_time)
31
- @current_test_path = nil
35
+ reset_timer
32
36
  end
33
37
 
34
38
  execution_time
35
39
  end
36
40
 
37
41
  def current_test_path
38
- KnapsackPro::TestFileCleaner.clean(@current_test_path) if @current_test_path
42
+ raise("current_test_path needs to be set by Knapsack Pro Adapter's bind method") unless @current_test_path
43
+ KnapsackPro::TestFileCleaner.clean(@current_test_path)
39
44
  end
40
45
 
41
46
  def set_prerun_tests(test_file_paths)
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '2.15.0'
2
+ VERSION = '2.16.0'
3
3
  end
@@ -87,16 +87,20 @@ describe KnapsackPro::Adapters::RSpecAdapter do
87
87
 
88
88
  it 'records time for current test path' do
89
89
  expect(config).to receive(:prepend_before).with(:context).and_yield
90
+
91
+ allow(KnapsackPro).to receive(:tracker).and_return(tracker)
92
+ expect(tracker).to receive(:start_timer).ordered
93
+
90
94
  expect(config).to receive(:around).with(:each).and_yield(example)
91
95
  expect(config).to receive(:append_after).with(:context).and_yield
92
96
  expect(config).to receive(:after).with(:suite).and_yield
93
97
  expect(::RSpec).to receive(:configure).and_yield(config)
94
98
 
99
+ expect(tracker).to receive(:stop_timer).ordered
100
+
95
101
  expect(::RSpec).to receive(:current_example).twice.and_return(current_example)
96
102
  expect(described_class).to receive(:test_path).with(example_group).and_return(test_path)
97
103
 
98
- allow(KnapsackPro).to receive(:tracker).and_return(tracker)
99
- expect(tracker).to receive(:start_timer).ordered
100
104
  expect(tracker).to receive(:current_test_path=).with(test_path).ordered
101
105
 
102
106
  expect(example).to receive(:run)
@@ -127,16 +131,20 @@ describe KnapsackPro::Adapters::RSpecAdapter do
127
131
  expect(example).to receive(:id).and_return(test_example_path)
128
132
 
129
133
  expect(config).to receive(:prepend_before).with(:context).and_yield
134
+
135
+ allow(KnapsackPro).to receive(:tracker).and_return(tracker)
136
+ expect(tracker).to receive(:start_timer).ordered
137
+
130
138
  expect(config).to receive(:around).with(:each).and_yield(example)
131
139
  expect(config).to receive(:append_after).with(:context).and_yield
132
140
  expect(config).to receive(:after).with(:suite).and_yield
133
141
  expect(::RSpec).to receive(:configure).and_yield(config)
134
142
 
143
+ expect(tracker).to receive(:stop_timer).ordered
144
+
135
145
  expect(::RSpec).to receive(:current_example).twice.and_return(current_example)
136
146
  expect(described_class).to receive(:test_path).with(example_group).and_return(test_path)
137
147
 
138
- allow(KnapsackPro).to receive(:tracker).and_return(tracker)
139
- expect(tracker).to receive(:start_timer).ordered
140
148
  expect(tracker).to receive(:current_test_path=).with(test_example_path).ordered
141
149
 
142
150
  expect(example).to receive(:run)
@@ -158,6 +166,10 @@ describe KnapsackPro::Adapters::RSpecAdapter do
158
166
 
159
167
  it 'records time for current test path' do
160
168
  expect(config).to receive(:prepend_before).with(:context).and_yield
169
+
170
+ allow(KnapsackPro).to receive(:tracker).and_return(tracker)
171
+ expect(tracker).to receive(:start_timer).ordered
172
+
161
173
  expect(config).to receive(:around).with(:each).and_yield(example)
162
174
  expect(config).to receive(:append_after).with(:context).and_yield
163
175
  expect(config).to receive(:after).with(:suite).and_yield
@@ -166,8 +178,8 @@ describe KnapsackPro::Adapters::RSpecAdapter do
166
178
  expect(::RSpec).to receive(:current_example).twice.and_return(current_example)
167
179
  expect(described_class).to receive(:test_path).with(example_group).and_return(test_path)
168
180
 
169
- allow(KnapsackPro).to receive(:tracker).and_return(tracker)
170
- expect(tracker).to receive(:start_timer).ordered
181
+ expect(tracker).to receive(:stop_timer).ordered
182
+
171
183
  expect(tracker).to receive(:current_test_path=).with(test_path).ordered
172
184
 
173
185
  expect(example).to receive(:run)
@@ -12,7 +12,9 @@ describe KnapsackPro::Tracker do
12
12
  subject { tracker.current_test_path }
13
13
 
14
14
  context 'when current_test_path not set' do
15
- it { expect(subject).to be_nil }
15
+ it do
16
+ expect { subject }.to raise_error("current_test_path needs to be set by Knapsack Pro Adapter's bind method")
17
+ end
16
18
  end
17
19
 
18
20
  context 'when current_test_path set' do
@@ -56,9 +58,6 @@ describe KnapsackPro::Tracker do
56
58
  it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
57
59
  it { expect(tracker.test_files_with_time['a_spec.rb'][:time_execution]).to be_within(delta).of(0.1) }
58
60
  it { expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to be_within(delta).of(0.2) }
59
- it 'resets current_test_path after time is measured' do
60
- expect(tracker.current_test_path).to be_nil
61
- end
62
61
  it_behaves_like '#to_a'
63
62
  end
64
63
 
@@ -84,9 +83,6 @@ describe KnapsackPro::Tracker do
84
83
  it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
85
84
  it { expect(tracker.test_files_with_time['a_spec.rb'][:time_execution]).to be_within(delta).of(0) }
86
85
  it { expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to be_within(delta).of(0) }
87
- it 'resets current_test_path after time is measured' do
88
- expect(tracker.current_test_path).to be_nil
89
- end
90
86
  it_behaves_like '#to_a'
91
87
  end
92
88
 
@@ -99,10 +95,12 @@ describe KnapsackPro::Tracker do
99
95
  end
100
96
  end
101
97
 
102
- it { expect(tracker.global_time).to eq 0 }
98
+ it { expect(tracker.global_time).to be > 0 }
103
99
  it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
104
100
  it { expect(tracker.test_files_with_time['a_spec.rb'][:time_execution]).to eq 0 }
105
- it { expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to eq 0 }
101
+ it '2nd spec (b_spec.rb) should have recorded time execution - because start_time was set during first call of stop_timer for the first spec (a_spec.rb)' do
102
+ expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to be > 0
103
+ end
106
104
  it_behaves_like '#to_a'
107
105
  end
108
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-20 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake