rspeed 0.1.0 → 0.2.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: fa530fc36a8a38f31b2f241cb0c322bd268f0928cb5929f89d4b939e54b740a3
4
- data.tar.gz: 4228e7997bd6d4b51da7aa66ef10ddc25474a184cd3c42d42afd6077db777f8d
3
+ metadata.gz: 27a64c0a7ba3f1c113bbdf8f060be44dad913a684d234663b342a537937ac7f2
4
+ data.tar.gz: 47d3a190302b361c6bb76279094a7c04982492e59d099d6acdbe92fcbd26d648
5
5
  SHA512:
6
- metadata.gz: ce7fa5fe6f56cdf9b3f9a02cc040a8180d21e3c5ad1c08bcc792df3ee336c300c6fd5d8438cef908815a896dc961a5743910a63686653c6fdc91707ec24b4a6b
7
- data.tar.gz: ae309883ef9f2f63792644583c1b9277e8c290e84172b59e7eecb0a961015d48b9411a798a6514d6dd3855a3553ce4d31e420634514f37025f4023a4c181e133
6
+ metadata.gz: ac35df999459a32e06989e84d0e703f52a61b896e3a68ef7993c6eaf70952dd05826dffdf36f01fe5843b3916e57b24112708cbcadd19b83eb018c990f2bda4c
7
+ data.tar.gz: '09feaa28dc6a306f8ba039bcfbf02b500450b6f117160a726f326daae76c9584524825ffd693a4f3a84a61cb181fef7c00216557ce04ccaea736f42d3e9370d8'
@@ -1,3 +1,7 @@
1
+ ## v0.2.0
2
+
3
+ - Splits specs by examples over files;
4
+
1
5
  ## v0.1.0
2
6
 
3
7
  - First release;
@@ -6,5 +6,6 @@ module RSpeed
6
6
  end
7
7
 
8
8
  require 'rspeed/extension'
9
+ require 'rspeed/observer'
9
10
  require 'rspeed/runner'
10
11
  require 'rspeed/splitter'
@@ -4,40 +4,8 @@ if ENV['RSPEED'] == 'true'
4
4
  require 'rspec/rails'
5
5
 
6
6
  RSpec.configure do |config|
7
- config.before :suite do
8
- File.open('rspeed.csv', 'w') { |file| file.truncate 0 }
9
- end
10
-
11
- config.before do |example|
12
- example.update_inherited_metadata start_at: example.clock.now
13
- end
14
-
15
- config.after do |example|
16
- file_path = example.metadata[:file_path]
17
- time_difference = example.clock.now - example.metadata[:start_at]
18
-
19
- File.open('rspeed.csv', 'a') do |file|
20
- file.write "#{time_difference},#{file_path}\n"
21
- end
22
- end
23
-
24
- config.after :suite do |_example|
25
- result = {}
26
-
27
- CSV.read('rspeed.csv').each do |line|
28
- result[line[1]] ||= 0
29
- result[line[1]] += line[0].to_d
30
- end
31
-
32
- result = result.sort_by { |line| line[1] }.reverse
33
-
34
- File.open('rspeed.csv', 'w') { |file| file.truncate 0 }
35
-
36
- File.open('rspeed.csv', 'a') do |file|
37
- result.each do |file_spec, time|
38
- file.write "#{time},#{file_spec}\n"
39
- end
40
- end
41
- end
7
+ config.before(:suite) { RSpeed::Observer.before_suite }
8
+ config.before { |example| RSpeed::Observer.before(example) }
9
+ config.after { |example| RSpeed::Observer.after(example) }
42
10
  end
43
11
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Observer
5
+ module_function
6
+
7
+ def after(example)
8
+ file_path = example.metadata[:file_path]
9
+ line_number = example.metadata[:line_number]
10
+ spent_time = example.clock.now - example.metadata[:start_at]
11
+
12
+ File.open('rspeed.csv', 'a') do |file|
13
+ file.write "#{spent_time},#{file_path}:#{line_number}\n"
14
+ end
15
+ end
16
+
17
+ def before(example)
18
+ example.update_inherited_metadata(start_at: example.clock.now)
19
+ end
20
+
21
+ def before_suite
22
+ truncate_csv_file
23
+ end
24
+
25
+ def truncate_csv_file
26
+ File.open('rspeed.csv', 'w') { |file| file.truncate(0) }
27
+ end
28
+ end
29
+ end
@@ -80,7 +80,9 @@ module RSpeed
80
80
  json["rspeed_#{index + 1}".to_sym] = { total: 0, files: [], number: index + 1 }
81
81
  end
82
82
 
83
- data.each do |record|
83
+ sorted_data = data.sort_by { |item| item[:time] }.reverse
84
+
85
+ sorted_data.each do |record|
84
86
  selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
85
87
  selected_pipe = json["rspeed_#{selected_pipe_data[1][:number]}".to_sym]
86
88
  time = record[:time].to_f
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpeed
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RSpeed::Observer, '.after' do
6
+ let!(:now) { Time.local(2020, 1, 1, 0, 0, 1) }
7
+ let!(:clock) { class_double(RSpec::Core::Time, now: now) }
8
+ let!(:metadata) { { file_path: 'file_path', line_number: 7, start_at: now - 1 } }
9
+ let!(:example) { instance_double(RSpec::Core::Example, clock: clock, metadata: metadata) }
10
+
11
+ before { clean_csv_file }
12
+
13
+ it 'appends the time of example on csv file' do
14
+ described_class.after(example)
15
+
16
+ expect(File.open('rspeed.csv').read).to eq "1.0,file_path:7\n"
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RSpeed::Observer, '.before' do
6
+ let!(:now) { Time.local(2020) }
7
+ let!(:clock) { class_double(RSpec::Core::Time, now: now) }
8
+ let!(:example) { instance_double(RSpec::Core::Example, clock: clock) }
9
+
10
+ it 'saves the current time' do
11
+ allow(example).to receive(:update_inherited_metadata)
12
+
13
+ described_class.before(example)
14
+
15
+ expect(example).to have_received(:update_inherited_metadata).with(start_at: now)
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RSpeed::Observer, '.before_suite' do
6
+ before { clean_csv_file }
7
+
8
+ it 'cleans the csv file' do
9
+ File.open('rspeed.csv', 'a') { |file| file.write('content') }
10
+
11
+ described_class.before_suite
12
+
13
+ expect(File.open('rspeed.csv').read).to eq ''
14
+ end
15
+ end
@@ -15,6 +15,11 @@ RSpec.describe RSpeed::Splitter, '#append' do
15
15
  end
16
16
 
17
17
  context 'when files is not given' do
18
+ before do
19
+ clean_csv_file
20
+ populate_csv_file
21
+ end
22
+
18
23
  it 'read csv and append file and time on rspeed key' do
19
24
  splitter.append
20
25
 
@@ -5,22 +5,22 @@ require 'rails_helper'
5
5
  RSpec.describe RSpeed::Splitter, '.split' do
6
6
  subject(:splitter) { described_class.new }
7
7
 
8
- let!(:data) do
8
+ let!(:unsorted_data) do
9
9
  [
10
- { file: './spec/2_0_spec.rb', time: '2.0' },
11
10
  { file: './spec/1_5_spec.rb', time: '1.5' },
12
11
  { file: './spec/1_1_spec.rb', time: '1.1' },
13
12
  { file: './spec/0_7_spec.rb', time: '0.7' },
14
13
  { file: './spec/0_4_spec.rb', time: '0.4' },
15
14
  { file: './spec/0_3_spec.rb', time: '0.3' },
16
15
  { file: './spec/0_2_spec.rb', time: '0.2' },
16
+ { file: './spec/2_0_spec.rb', time: '2.0' },
17
17
  ]
18
18
  end
19
19
 
20
20
  before { allow(splitter).to receive(:pipes).and_return 3 }
21
21
 
22
22
  it 'splits the times between the pipes' do
23
- expect(splitter.split(data)).to eq(
23
+ expect(splitter.split(unsorted_data)).to eq(
24
24
  rspeed_1: {
25
25
  files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
26
26
  number: 1,
@@ -9,14 +9,33 @@ require 'rspec'
9
9
  require 'rspeed'
10
10
 
11
11
  RSpec.configure do |config|
12
+ config.after do
13
+ ENV.delete('RSPEED_PIPE')
14
+ ENV.delete('RSPEED_PIPES')
15
+ end
16
+
12
17
  config.disable_monkey_patching!
13
18
 
14
19
  config.order = :random
20
+ config.profile_examples = 10
21
+ end
15
22
 
16
- config.after do
17
- ENV.delete 'RSPEED_PIPE'
18
- ENV.delete 'RSPEED_PIPES'
19
- end
23
+ def clean_csv_file
24
+ File.open('rspeed.csv', 'w') { |file| file.truncate(0) }
25
+ end
26
+
27
+ def populate_csv_file
28
+ data = [
29
+ '2.0,./spec/2_0_spec.rb',
30
+ '1.5,./spec/1_5_spec.rb',
31
+ '1.1,./spec/1_1_spec.rb',
32
+ '0.7,./spec/0_7_spec.rb',
33
+ '0.4,./spec/0_4_spec.rb',
34
+ '0.3,./spec/0_3_spec.rb',
35
+ '0.2,./spec/0_2_spec.rb'
36
+ ].join("\n")
37
+
38
+ File.open('rspeed.csv', 'a') { |file| file.write(data) }
20
39
  end
21
40
 
22
41
  def redis_object
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspeed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-07 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -110,9 +110,13 @@ files:
110
110
  - lib/generators/rspeed/templates/lib/tasks/rspeed.rb
111
111
  - lib/rspeed.rb
112
112
  - lib/rspeed/extension.rb
113
+ - lib/rspeed/observer.rb
113
114
  - lib/rspeed/runner.rb
114
115
  - lib/rspeed/splitter.rb
115
116
  - lib/rspeed/version.rb
117
+ - spec/models/rspeed/observer/after_spec.rb
118
+ - spec/models/rspeed/observer/before_spec.rb
119
+ - spec/models/rspeed/observer/before_suite_spec.rb
116
120
  - spec/models/rspeed/splitter/append_spec.rb
117
121
  - spec/models/rspeed/splitter/destroy_spec.rb
118
122
  - spec/models/rspeed/splitter/diff_spec.rb
@@ -164,4 +168,7 @@ test_files:
164
168
  - spec/models/rspeed/splitter/diff_spec.rb
165
169
  - spec/models/rspeed/splitter/split_spec.rb
166
170
  - spec/models/rspeed/splitter/pipes_spec.rb
171
+ - spec/models/rspeed/observer/before_suite_spec.rb
172
+ - spec/models/rspeed/observer/before_spec.rb
173
+ - spec/models/rspeed/observer/after_spec.rb
167
174
  - spec/rails_helper.rb