knapsack 1.0.2 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e65fdc9823d7ad10bb38a4d96663526897528565
4
- data.tar.gz: ac938b8d273c278c79b87b961a48edd716c0f8a5
3
+ metadata.gz: 7c687c34dd940bdf5c7594c114be9332548944ff
4
+ data.tar.gz: 38a10eaa09e1b6b87d4110a5c6173997f6dd73f2
5
5
  SHA512:
6
- metadata.gz: 67cfb99f75768e27301dc1d0446c5950b8d97640eec3f98062832004d0c2be2931cc2f0421c641817ed50c713fb464a3ee059208fb4bb18d0e58065015f16a18
7
- data.tar.gz: 70bf4d8fe18658b1dbeece948208c7b1d2d147384fe59564546976d2b8a1775638ae0cd113d3fc873143b5e3259f5d4e69355ae69d087ba13a6939a15f140c40
6
+ metadata.gz: 4f4784ef9d81e7b1110269a1b280fdc7fd9b4ce8c16c08612c91a6524754d4e1c35a9fe88512b7d5512d03c26423bd70d2bea7eea15949b06d7eebb728800077
7
+ data.tar.gz: 6121b44a1c65b71d0a3c44478889cdfd80104448defcefe1b65f0a294b03fb38d6cfb4742e759bc4162ca71d8e54c25375fcb1578a224c87f527d05b7f831cb3
@@ -2,6 +2,14 @@
2
2
 
3
3
  * TODO
4
4
 
5
+ ### 1.0.3
6
+
7
+ * Fix bug #11 - Track properly time when using Timecop gem in tests.
8
+
9
+ https://github.com/ArturT/knapsack/issues/11
10
+
11
+ https://github.com/ArturT/knapsack/issues/9
12
+
5
13
  ### 1.0.2
6
14
 
7
15
  * Fix bug #8 - Sort all tests just in case to avoid wrong order of files when running tests on machines where `Dir.glob` has different implementation.
@@ -19,11 +19,11 @@ module Knapsack
19
19
  end
20
20
 
21
21
  def start_timer
22
- @start_time = Time.now.to_f
22
+ @start_time = now_without_mock_time.to_f
23
23
  end
24
24
 
25
25
  def stop_timer
26
- @execution_time = Time.now.to_f - @start_time
26
+ @execution_time = now_without_mock_time.to_f - @start_time
27
27
  update_global_time
28
28
  update_test_file_time
29
29
  @execution_time
@@ -79,5 +79,15 @@ module Knapsack
79
79
  ci_node_index: Knapsack::Config::Env.ci_node_index
80
80
  })
81
81
  end
82
+
83
+ private
84
+
85
+ def now_without_mock_time
86
+ if defined?(Timecop)
87
+ Time.now_without_mock_time
88
+ else
89
+ Time.now
90
+ end
91
+ end
82
92
  end
83
93
  end
@@ -1,3 +1,3 @@
1
1
  module Knapsack
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -118,34 +118,67 @@ describe Knapsack::Tracker do
118
118
  end
119
119
 
120
120
  describe 'track time execution' do
121
- let(:now) { Time.now }
122
121
  let(:test_paths) { ['a_spec.rb', 'b_spec.rb'] }
122
+ let(:delta) { 0.02 }
123
123
 
124
- before do
125
- test_paths.each_with_index do |test_path, index|
126
- Timecop.freeze(now) do
124
+ shared_examples 'test tracker' do
125
+ it { expect(tracker.global_time).to be_within(delta).of(0.3) }
126
+ it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
127
+ it { expect(tracker.test_files_with_time['a_spec.rb']).to be_within(delta).of(0.1) }
128
+ it { expect(tracker.test_files_with_time['b_spec.rb']).to be_within(delta).of(0.2) }
129
+ end
130
+
131
+ context 'without Timecop' do
132
+ before do
133
+ test_paths.each_with_index do |test_path, index|
127
134
  tracker.test_path = test_path
128
135
  tracker.start_timer
129
- end
130
-
131
- seconds = index + 1
132
- Timecop.freeze(now+seconds) do
136
+ sleep index.to_f / 10 + 0.1
133
137
  tracker.stop_timer
134
138
  end
135
139
  end
140
+
141
+ it { expect(tracker.global_time).to be_within(delta).of(0.3) }
142
+ it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
143
+ it { expect(tracker.test_files_with_time['a_spec.rb']).to be_within(delta).of(0.1) }
144
+ it { expect(tracker.test_files_with_time['b_spec.rb']).to be_within(delta).of(0.2) }
136
145
  end
137
146
 
138
- it { expect(tracker.global_time).to eql 3.0 }
139
- it do
140
- expect(tracker.test_files_with_time).to eql({
141
- 'a_spec.rb' => 1.0,
142
- 'b_spec.rb' => 2.0,
143
- })
147
+ context "with Timecop - Timecop shouldn't have impact on measured test time" do
148
+ let(:now) { Time.now }
149
+
150
+ before do
151
+ test_paths.each_with_index do |test_path, index|
152
+ Timecop.freeze(now) do
153
+ tracker.test_path = test_path
154
+ tracker.start_timer
155
+ end
156
+
157
+ delay = index + 1
158
+ Timecop.freeze(now+delay) do
159
+ tracker.stop_timer
160
+ end
161
+ end
162
+ end
163
+
164
+ it { expect(tracker.global_time).to be >= 0 }
165
+ it { expect(tracker.global_time).to be_within(delta).of(0) }
166
+ it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
167
+ it { expect(tracker.test_files_with_time['a_spec.rb']).to be_within(delta).of(0) }
168
+ it { expect(tracker.test_files_with_time['b_spec.rb']).to be_within(delta).of(0) }
144
169
  end
170
+ end
145
171
 
146
- context '#reset!' do
147
- before { tracker.reset! }
148
- it_behaves_like 'default trakcer attributes'
172
+ describe '#reset!' do
173
+ before do
174
+ tracker.test_path = 'a_spec.rb'
175
+ tracker.start_timer
176
+ sleep 0.1
177
+ tracker.stop_timer
178
+ expect(tracker.global_time).not_to eql 0
179
+ tracker.reset!
149
180
  end
181
+
182
+ it_behaves_like 'default trakcer attributes'
150
183
  end
151
184
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler