rspeed 0.3.0 → 0.4.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: 19e3b06a0f6189661598a3db76e740b99b5ab658b3e08119fa6f8a74efb74552
4
- data.tar.gz: 813bd8934d23e84bcb0facf56da0bf53c4017d5af03337989a42ffff2dac679d
3
+ metadata.gz: 9f8fbbef694a5ee56e51580e9969e9e8372d4d93d0e5562f4efbad08fb8df854
4
+ data.tar.gz: b9cefcd95a86536bcd139ef8df7f47674ad0f4205ecfb0c7bc7dd2b5c33b4efd
5
5
  SHA512:
6
- metadata.gz: '004081032114288e16f23c176ca49c03e85274ed6b91272144643452ec5f2a648c829dae5539c94215897f67482a6f0cf1e5253acabeafc6cdf5a6e2fe2681e9'
7
- data.tar.gz: 2ec7f4991a5702f4bd24000e71eb5426969f0abd3a77cabd521887ad72dac3e3ec5f28f0165193ca806f8e9a9e8fce712ac9923f899c9e8767c8808320400ab4
6
+ metadata.gz: 66a0fba65b3130c9454abad42a8a0e4554fd49711194a74cf7d5d77d37274469500e29f0d6210c53d92f33aa529799d416281c5556f193b9a9c0a96d3b7babbd
7
+ data.tar.gz: 59399ef9100cc2353a7dc93b53a152289b79aaac9a5c2ace44925a50c517a94196193ebe25ae5a4148861ace0317dfdd2def59b332ab9c717b6d073dad5df0c0
@@ -1,3 +1,7 @@
1
+ ## v0.4.0
2
+
3
+ - Now we make diff to discover removed and added examples;
4
+
1
5
  ## v0.3.0
2
6
 
3
7
  - Removed and added files now is considered on run;
@@ -1,9 +1,31 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module RSpeed
3
4
  class Splitter
4
5
  DEFAULT_PATTERN = 'rspeed_*'
5
6
 
6
- def append(files = file_data)
7
+ def initialize(specs_path: './spec/**/*_spec.rb')
8
+ @specs_path = specs_path
9
+ end
10
+
11
+ def actual_examples
12
+ @actual_examples ||= begin
13
+ [].tap do |examples|
14
+ Dir[@specs_path].each do |file|
15
+ data = File.open(file).read
16
+ lines = data.split("\n")
17
+
18
+ lines&.each.with_index do |item, index|
19
+ examples << "#{file}:#{index + 1}" if item.gsub(/\s+/, '') =~ /^it/
20
+ end
21
+ end
22
+
23
+ stream(:actual_examples, examples)
24
+ end
25
+ end
26
+ end
27
+
28
+ def append(files = CSV.read('rspeed.csv'))
7
29
  files.each do |time, file|
8
30
  redis.lpush('rspeed_tmp', { file: file, time: time.to_f }.to_json)
9
31
  end
@@ -14,6 +36,11 @@ module RSpeed
14
36
  end
15
37
 
16
38
  def diff
39
+ actual_data = rspeed_data.select { |item| actual_examples.include?(item[:file]) }
40
+ added_data = added_examples.map { |item| { file: item, time: 0 } }
41
+
42
+ removed_examples # called just for stream for now
43
+
17
44
  actual_data + added_data
18
45
  end
19
46
 
@@ -91,44 +118,36 @@ module RSpeed
91
118
 
92
119
  private
93
120
 
94
- def actual_data
95
- rspeed_data.select { |item| actual_files.include?(item[:file]) }
96
- end
97
-
98
- def actual_files
99
- @actual_files ||= Dir['./spec/**/*_spec.rb']
100
- end
101
-
102
- def added_data
103
- added_specs.map { |item| { file: item, time: 0 } }
104
- end
105
-
106
- def added_specs
107
- actual_files - old_files
108
- end
109
-
110
- def file_data
111
- CSV.read('rspeed.csv')
112
- end
113
-
114
- def old_files
115
- rspeed_data.map { |item| item[:file] }
121
+ def added_examples
122
+ @added_examples ||= begin
123
+ (actual_examples - rspeed_examples).tap { |examples| stream(:added_examples, examples) }
124
+ end
116
125
  end
117
126
 
118
127
  def redis
119
128
  @redis ||= ::Redis.new(db: ENV['RSPEED_DB'], host: ENV['RSPEED_HOST'], port: ENV.fetch('RSPEED_PORT') { 6379 })
120
129
  end
121
130
 
122
- def removed_specs
123
- old_files - actual_files
131
+ def removed_examples
132
+ @removed_examples ||= begin
133
+ (rspeed_examples - actual_examples).tap { |examples| stream(:removed_examples, examples) }
134
+ end
124
135
  end
125
136
 
126
137
  def removed_time
127
- removed_specs.map { |item| item[0].to_f }.sum
138
+ removed_examples.map { |item| item[0].to_f }.sum
128
139
  end
129
140
 
130
141
  def rspeed_data
131
142
  @rspeed_data ||= get('rspeed').map { |item| JSON.parse(item, symbolize_names: true) }
132
143
  end
144
+
145
+ def rspeed_examples
146
+ rspeed_data.map { |item| item[:file] }
147
+ end
148
+
149
+ def stream(type, data)
150
+ puts "PIPE: #{pipe} with #{type}: #{data}"
151
+ end
133
152
  end
134
153
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpeed
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'fixture_1' do
4
+ it { sleep 0.1 }
5
+
6
+ it { sleep 0.2 }
7
+
8
+ it { sleep 0.3 }
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'fixture_2' do
4
+ it { sleep 2 }
5
+ end
@@ -0,0 +1 @@
1
+ 10,./spec/fixtures/new_spec.rb.csv:1010,./spec/fixtures/new_spec.rb.csv:10
@@ -8,7 +8,7 @@ RSpec.describe RSpeed::Observer, '.after' do
8
8
  let!(:metadata) { { file_path: 'file_path', line_number: 7, start_at: now - 1 } }
9
9
  let!(:example) { instance_double(RSpec::Core::Example, clock: clock, metadata: metadata) }
10
10
 
11
- before { clean_csv_file }
11
+ before { truncate_file }
12
12
 
13
13
  it 'appends the time of example on csv file' do
14
14
  described_class.after(example)
@@ -3,7 +3,7 @@
3
3
  require 'rails_helper'
4
4
 
5
5
  RSpec.describe RSpeed::Observer, '.before_suite' do
6
- before { clean_csv_file }
6
+ before { truncate_file }
7
7
 
8
8
  it 'cleans the csv file' do
9
9
  File.open('rspeed.csv', 'a') { |file| file.write('content') }
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RSpeed::Splitter, '#actual_examples' do
6
+ it 'returns all examples' do
7
+ splitter = described_class.new(specs_path: 'spec/fixtures/**/*_spec.rb')
8
+
9
+ expect(splitter.actual_examples).to eq [
10
+ 'spec/fixtures/1_spec.rb:4',
11
+ 'spec/fixtures/1_spec.rb:6',
12
+ 'spec/fixtures/1_spec.rb:8',
13
+ 'spec/fixtures/2_spec.rb:4',
14
+ ]
15
+ end
16
+
17
+ it 'does not raise when no file match' do
18
+ splitter = described_class.new(specs_path: 'spec/fixtures/**/*_missing.rb')
19
+
20
+ expect(splitter.actual_examples).to eq []
21
+ end
22
+ end
@@ -16,7 +16,7 @@ RSpec.describe RSpeed::Splitter, '#append' do
16
16
 
17
17
  context 'when files is not given' do
18
18
  before do
19
- clean_csv_file
19
+ truncate_file
20
20
  populate_csv_file
21
21
  end
22
22
 
@@ -3,27 +3,30 @@
3
3
  require 'rails_helper'
4
4
 
5
5
  RSpec.describe RSpeed::Splitter, '#diff' do
6
- subject(:splitter) { described_class.new }
6
+ subject(:splitter) { described_class.new(specs_path: './spec/fixtures/*_spec.rb') }
7
7
 
8
8
  let!(:redis) { redis_object }
9
9
 
10
10
  before do
11
- redis.lpush 'rspeed', { file: '1_spec.rb', time: 1 }.to_json
12
- redis.lpush 'rspeed', { file: '2_spec.rb', time: 2 }.to_json
13
- redis.lpush 'rspeed', { file: '3_spec.rb', time: 3 }.to_json
11
+ redis.lpush 'rspeed', { file: './spec/fixtures/1_spec.rb:4', time: '1.4' }.to_json
12
+ redis.lpush 'rspeed', { file: './spec/fixtures/1_spec.rb:6', time: '1.6' }.to_json
13
+ redis.lpush 'rspeed', { file: './spec/fixtures/1_spec.rb:8', time: '1.8' }.to_json
14
+ redis.lpush 'rspeed', { file: './spec/fixtures/2_spec.rb:4', time: '2.4' }.to_json
15
+ redis.lpush 'rspeed', { file: './spec/fixtures/2_spec.rb:666', time: '6' }.to_json
16
+ redis.lpush 'rspeed', { file: './spec/fixtures/x_spec.rb:1', time: 3 }.to_json
14
17
 
15
- allow(Dir).to receive(:[]).with('./spec/**/*_spec.rb').and_return %w[
16
- 2_spec.rb
17
- 3_spec.rb
18
- 4_spec.rb
19
- ]
18
+ File.open('spec/fixtures/new_spec.rb', 'a') { |file| file.write("it") }
20
19
  end
21
20
 
21
+ after { delete_file('spec/fixtures/new_spec.rb') }
22
+
22
23
  it 'removes removed specs and adds new spec and keeps keeped specs based on rspeed key values' do
23
24
  expect(splitter.diff).to eq [
24
- { file: '3_spec.rb', time: 3 },
25
- { file: '2_spec.rb', time: 2 },
26
- { file: '4_spec.rb', time: 0 },
25
+ { file: './spec/fixtures/2_spec.rb:4', time: '2.4' },
26
+ { file: './spec/fixtures/1_spec.rb:8', time: '1.8' },
27
+ { file: './spec/fixtures/1_spec.rb:6', time: '1.6' },
28
+ { file: './spec/fixtures/1_spec.rb:4', time: '1.4' },
29
+ { file: './spec/fixtures/new_spec.rb:1', time: 0 },
27
30
  ]
28
31
  end
29
32
  end
@@ -20,8 +20,12 @@ RSpec.configure do |config|
20
20
  config.profile_examples = 10
21
21
  end
22
22
 
23
- def clean_csv_file
24
- File.open('rspeed.csv', 'w') { |file| file.truncate(0) }
23
+ def delete_file(file_path = 'rspeed.csv')
24
+ File.delete(file_path) if File.exist?(file_path)
25
+ end
26
+
27
+ def truncate_file(file_path = 'rspeed.csv')
28
+ File.open(file_path, 'w') { |file| file.truncate(0) }
25
29
  end
26
30
 
27
31
  def populate_csv_file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspeed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
@@ -114,9 +114,13 @@ files:
114
114
  - lib/rspeed/runner.rb
115
115
  - lib/rspeed/splitter.rb
116
116
  - lib/rspeed/version.rb
117
+ - spec/fixtures/1_spec.rb
118
+ - spec/fixtures/2_spec.rb
119
+ - spec/fixtures/new_spec.rb.csv
117
120
  - spec/models/rspeed/observer/after_spec.rb
118
121
  - spec/models/rspeed/observer/before_spec.rb
119
122
  - spec/models/rspeed/observer/before_suite_spec.rb
123
+ - spec/models/rspeed/splitter/actual_examples_spec.rb
120
124
  - spec/models/rspeed/splitter/append_spec.rb
121
125
  - spec/models/rspeed/splitter/destroy_spec.rb
122
126
  - spec/models/rspeed/splitter/diff_spec.rb
@@ -158,6 +162,7 @@ test_files:
158
162
  - spec/models/rspeed/splitter/append_spec.rb
159
163
  - spec/models/rspeed/splitter/destroy_spec.rb
160
164
  - spec/models/rspeed/splitter/pipe_spec.rb
165
+ - spec/models/rspeed/splitter/actual_examples_spec.rb
161
166
  - spec/models/rspeed/splitter/get_spec.rb
162
167
  - spec/models/rspeed/splitter/rename_spec.rb
163
168
  - spec/models/rspeed/splitter/last_pipe_spec.rb
@@ -171,4 +176,7 @@ test_files:
171
176
  - spec/models/rspeed/observer/before_suite_spec.rb
172
177
  - spec/models/rspeed/observer/before_spec.rb
173
178
  - spec/models/rspeed/observer/after_spec.rb
179
+ - spec/fixtures/new_spec.rb.csv
180
+ - spec/fixtures/1_spec.rb
181
+ - spec/fixtures/2_spec.rb
174
182
  - spec/rails_helper.rb