rspeed 0.6.0 → 0.7.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: 5b8a143543e9f44b4c5641d60642968b7cc4a7ec85953b17f6ef62743e66196e
4
- data.tar.gz: f8fc781825804fe67084c08b05164ca8a31fc87e458952ba0ca86e567576e669
3
+ metadata.gz: 121d5558331de345c2147e1b1ee8b6679c09ac8cb83b33af4ad5673d3e534806
4
+ data.tar.gz: b739938586f9ce82c94c9fe74f79583153ad268e5443c54602f32650482595dd
5
5
  SHA512:
6
- metadata.gz: 7b50821b549363010ab566dd5f654a5b2b042e76fd696054b795126b1343ec3a8d73ed1c3a7a08cb63f1eeba38dbbae8922877bb8ec8649bb4601577b75737b0
7
- data.tar.gz: 0f74bea31bf0c550ce6f89b8f22e8c0fedb59acfebe6cddf1dc4fc4499b74e7e73505b4a24327948f1330d9ff46b16f70de0855b4178a452149b33d2b5396051
6
+ metadata.gz: 4109a7ca7ccc74e43c09eafd0aabf5fba559f9dbc5350a8439cbfc47cd400c03de3d862405059e60adb6ee11b83592985a89b877982c3094bcecbf3f69c363df
7
+ data.tar.gz: 6f706fe116da661fe858fc85979e5ee718ec4fe4da19cb13cd06ee6bbabad4688e6182f8504db93215a549fa9efe18991314faf97d8ca8e0f55125771b2de772
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  - None;
4
4
 
5
+ ## v0.7.0
6
+
7
+ #### News
8
+
9
+ - Prints pipe info into a table on the console;
10
+ - The previous result is keeped alive for further checks;
11
+ - Adds final report show actual, added and removed;
12
+
5
13
  ## v0.6.0
6
14
 
7
15
  #### Break Change
data/lib/rspeed.rb CHANGED
@@ -7,6 +7,7 @@ module RSpeed
7
7
  require 'rspeed/logger'
8
8
  require 'rspeed/observer'
9
9
  require 'rspeed/redis'
10
+ require 'rspeed/reporter'
10
11
  require 'rspeed/runner'
11
12
  require 'rspeed/splitter'
12
13
  require 'rspeed/variable'
@@ -4,8 +4,16 @@ module RSpeed
4
4
  module Database
5
5
  module_function
6
6
 
7
+ def previous_result
8
+ list(RSpeed::Variable.previous_result)
9
+ end
10
+
7
11
  def result
8
- RSpeed::Redis.list(RSpeed::Variable.result).map { |item| JSON.parse(item, symbolize_names: true) }
12
+ list(RSpeed::Variable.result)
13
+ end
14
+
15
+ def list(key)
16
+ RSpeed::Redis.list(key).map { |item| JSON.parse(item, symbolize_names: true) }
9
17
  end
10
18
  end
11
19
  end
data/lib/rspeed/differ.rb CHANGED
@@ -13,43 +13,59 @@ module RSpeed
13
13
  data << "#{file}:#{index + 1}" if /^it/.match?(item.gsub(/\s+/, ''))
14
14
  end
15
15
  end
16
-
17
- RSpeed::Logger.log(self, __method__, data)
18
16
  end
19
17
  end
20
18
 
21
19
  def actual_data(files:, result:)
22
- result
23
- .select { |item| files.include?(item[:file]) }
24
- .tap { |data| RSpeed::Logger.log(self, __method__, data) }
20
+ result.select { |item| files.include?(item[:file]) }
25
21
  end
26
22
 
27
23
  def added_data(files:, result:)
28
- (files - result.map { |item| item[:file] })
29
- .map { |file| { file: file, time: 0 } }
30
- .tap { |data| RSpeed::Logger.log(self, __method__, data) }
24
+ (files - result.map { |item| item[:file] }).map { |file| { file: file, time: nil } }
31
25
  end
32
26
 
33
- def diff
34
- files = actual_files
35
- result = RSpeed::Database.result.uniq { |item| item[:file] }
27
+ def diff(from: actual_files, to: RSpeed::Database.result)
28
+ to = to.uniq { |item| item[:file] }
29
+ added = added_data(files: from, result: to)
30
+ actual = actual_data(files: from, result: to) + added_data(files: from, result: to)
31
+ removed = removed_data(files: from, result: to)
32
+
33
+ {
34
+ actual_files: actual,
35
+ actual_time: sum_time(data: actual),
36
+ added_files: added,
37
+ added_time: sum_time(data: added),
38
+ removed_files: removed,
39
+ removed_time: sum_time(data: removed),
40
+ }
41
+ end
36
42
 
37
- removed_data(files: files, result: result) # called just for log purpose
43
+ def final_diff(from: RSpeed::Database.previous_result, to: RSpeed::Database.result)
44
+ from = from.uniq { |item| item[:file] }
45
+ to = to.uniq { |item| item[:file] }
46
+ previous_files = from.map { |item| item[:file] }
47
+ actual_files = to.map { |item| item[:file] }
48
+ added = to.reject { |item| previous_files.include?(item[:file]) }
49
+ removed = from.reject { |item| actual_files.include?(item[:file]) }
38
50
 
39
- (actual_data(files: files, result: result) + added_data(files: files, result: result))
40
- .tap { |data| RSpeed::Logger.log(self, __method__, data) }
51
+ {
52
+ actual_files: to,
53
+ actual_time: sum_time(data: to),
54
+ added_files: added,
55
+ added_time: sum_time(data: added),
56
+ removed_files: removed,
57
+ removed_time: sum_time(data: removed),
58
+ }
41
59
  end
42
60
 
43
61
  def removed_data(files:, result:)
44
- result
45
- .reject { |item| files.include?(item[:file]) }
46
- .tap { |data| RSpeed::Logger.log(self, __method__, data) }
62
+ result.reject { |item| files.include?(item[:file]) }
47
63
  end
48
64
 
49
- def removed_time(data:)
50
- data
51
- .sum { |item| item[:time].to_f }
52
- .tap { |result| RSpeed::Logger.log(self, __method__, result) }
65
+ def sum_time(data:)
66
+ return '?' if data.all? { |item| item[:time].nil? }
67
+
68
+ data.sum { |item| item[:time].to_f }
53
69
  end
54
70
  end
55
71
  end
@@ -19,8 +19,9 @@ module RSpeed
19
19
 
20
20
  return unless RSpeed::Redis.specs_finished?
21
21
 
22
+ RSpeed::Redis.version_the_result if RSpeed::Redis.result?
22
23
  RSpeed::Splitter.consolidate
23
-
24
+ RSpeed::Reporter.call
24
25
  RSpeed::Redis.clean
25
26
 
26
27
  RSpeed::Logger.log(self, __method__, 'RSpeed finished.')
@@ -31,10 +32,6 @@ module RSpeed
31
32
  end
32
33
 
33
34
  def before_suite
34
- clean_profile
35
- end
36
-
37
- def clean_profile
38
35
  RSpeed::Logger.log(self, __method__, 'Cleanning current flag and profile.')
39
36
 
40
37
  RSpeed::Redis.destroy(pattern: RSpeed::Variable.pipe)
data/lib/rspeed/redis.rb CHANGED
@@ -68,5 +68,11 @@ module RSpeed
68
68
  RSpeed::Logger.log(self, __method__, "Specs #{boo ? 'initialized.' : 'not initialized yet.'}")
69
69
  end
70
70
  end
71
+
72
+ def version_the_result
73
+ RSpeed::Logger.log(self, __method__, 'Versioning the result.')
74
+
75
+ client.rename(RSpeed::Variable.result, RSpeed::Variable.previous_result)
76
+ end
71
77
  end
72
78
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Reporter
5
+ module_function
6
+
7
+ require 'terminal-table'
8
+
9
+ def call
10
+ diff = RSpeed::Differ.final_diff
11
+
12
+ print_table(
13
+ headings: %w[Global Value],
14
+
15
+ rows: [
16
+ ['Actual Time', diff[:actual_time]],
17
+ ['Removed Time', diff[:removed_time]],
18
+ ['Added Time', diff[:added_time]],
19
+ ]
20
+ )
21
+ end
22
+
23
+ def print_files(items)
24
+ total_specs = items.size
25
+ headings = ["#{total_specs} specs", "Pipe #{RSpeed::Env.pipe}/#{RSpeed::Env.pipes}", 'Last Time']
26
+
27
+ rows = items.map.with_index do |item, index|
28
+ [format('%02d', index + 1), item[:file], item[:time].to_s]
29
+ end
30
+
31
+ print_table(headings: headings, rows: rows)
32
+ end
33
+
34
+ def print_table(headings:, rows:)
35
+ puts(Terminal::Table.new(headings: headings, rows: rows, title: 'RSpeed'))
36
+ end
37
+ end
38
+ end
data/lib/rspeed/runner.rb CHANGED
@@ -9,7 +9,7 @@ module RSpeed
9
9
  return shell.call(['bundle exec rspec', RSpeed::Splitter.pipe_files].compact.join(' '))
10
10
  end
11
11
 
12
- RSpeed::Logger.log(self, __method__, "Skipped! Only Pipe 1 can warm.")
12
+ RSpeed::Logger.log(self, __method__, 'Skipped! Only Pipe 1 can warm.')
13
13
 
14
14
  RSpeed::Observer.after_suite
15
15
  end
@@ -31,9 +31,11 @@ module RSpeed
31
31
  def pipe_files
32
32
  return unless RSpeed::Redis.result?
33
33
 
34
- splitted = split(data: RSpeed::Differ.diff)
34
+ splitted = split(data: RSpeed::Differ.diff[:actual_files])
35
35
 
36
- splitted[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].map { |item| item[:file] }.join(' ')
36
+ splitted[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].tap do |items|
37
+ RSpeed::Reporter.print_files(items)
38
+ end.map { |item| item[:file] }.join(' ')
37
39
  end
38
40
 
39
41
  def split(data:)
@@ -44,7 +46,7 @@ module RSpeed
44
46
  json[RSpeed::Variable.key(index + 1)] = { total: 0, files: [], number: index + 1 }
45
47
  end
46
48
 
47
- sorted_data = data.sort_by { |item| item[:time] }.reverse
49
+ sorted_data = data.sort_by { |item| item[:time] || 0.0 }.reverse
48
50
 
49
51
  sorted_data.each do |record|
50
52
  selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
@@ -23,6 +23,10 @@ module RSpeed
23
23
  append_app_name('rspeed:pipe', plus: format('%02d', RSpeed::Env.pipe))
24
24
  end
25
25
 
26
+ def previous_result
27
+ append_app_name('rspeed', plus: 'previous')
28
+ end
29
+
26
30
  def profile
27
31
  append_app_name('rspeed:profile', plus: format('%02d', RSpeed::Env.pipe))
28
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpeed
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Database, '#list' do
4
+ before do
5
+ redis_object.rpush(RSpeed::Variable.result, { file: '1_spec.rb', time: 1.0 }.to_json)
6
+ redis_object.rpush(RSpeed::Variable.result, { file: '2_spec.rb', time: 2.0 }.to_json)
7
+ end
8
+
9
+ it 'list and parse the given key' do
10
+ expect(described_class.list(RSpeed::Variable.result)).to eq [
11
+ { file: '1_spec.rb', time: 1.0 },
12
+ { file: '2_spec.rb', time: 2.0 },
13
+ ]
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Database, '#previous_result' do
4
+ let!(:redis) { redis_object }
5
+
6
+ before do
7
+ redis.rpush(RSpeed::Variable.previous_result, { file: '1_spec.rb', time: 1.0 }.to_json)
8
+ redis.rpush(RSpeed::Variable.previous_result, { file: '2_spec.rb', time: 2.0 }.to_json)
9
+ end
10
+
11
+ it 'returns the previous results data as json' do
12
+ expect(described_class.previous_result).to eq [
13
+ { file: '1_spec.rb', time: 1.0 },
14
+ { file: '2_spec.rb', time: 2.0 },
15
+ ]
16
+ end
17
+ end
@@ -11,9 +11,9 @@ RSpec.describe RSpeed::Differ, '#added_data' do
11
11
  ]
12
12
  end
13
13
 
14
- it 'returns the added data files with time as zero since we do not know yet' do
14
+ it 'returns the added data files' do
15
15
  expect(described_class.added_data(files: files, result: result)).to eq [
16
- { file: './spec/fixtures/new_spec.rb:4', time: 0 },
16
+ { file: './spec/fixtures/new_spec.rb:4', time: nil },
17
17
  ]
18
18
  end
19
19
  end
@@ -6,12 +6,12 @@ RSpec.describe RSpeed::Differ, '#diff' do
6
6
  let!(:redis) { redis_object }
7
7
 
8
8
  before do
9
- redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:4', time: '1.4' }.to_json)
10
- redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:6', time: '1.6' }.to_json)
11
- redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:8', time: '1.8' }.to_json)
12
- redis.rpush('rspeed', { file: './spec/fixtures/2_spec.rb:4', time: '2.4' }.to_json)
9
+ redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:4', time: 1.4 }.to_json)
10
+ redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:6', time: 1.6 }.to_json)
11
+ redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:8', time: 1.8 }.to_json)
12
+ redis.rpush('rspeed', { file: './spec/fixtures/2_spec.rb:4', time: 2.4 }.to_json)
13
13
  redis.rpush('rspeed', { file: './spec/fixtures/x_spec.rb:1', time: 3 }.to_json)
14
- redis.rpush('rspeed', { file: './spec/fixtures/2_spec.rb:666', time: '6' }.to_json)
14
+ redis.rpush('rspeed', { file: './spec/fixtures/2_spec.rb:666', time: 6 }.to_json)
15
15
 
16
16
  File.open('spec/fixtures/new_spec.rb', 'a') { |file| file.write('it') }
17
17
  end
@@ -20,31 +20,57 @@ RSpec.describe RSpeed::Differ, '#diff' do
20
20
 
21
21
  it 'removes removed specs and adds new spec and keeps keeped specs based on rspeed key values' do
22
22
  EnvMock.mock(rspeed_spec_path: './spec/fixtures/*_spec.rb') do
23
- expect(described_class.diff).to eq [
24
- { file: './spec/fixtures/1_spec.rb:4', time: '1.4' },
25
- { file: './spec/fixtures/1_spec.rb:6', time: '1.6' },
26
- { file: './spec/fixtures/1_spec.rb:8', time: '1.8' },
27
- { file: './spec/fixtures/2_spec.rb:4', time: '2.4' },
28
- { file: './spec/fixtures/new_spec.rb:1', time: 0 },
29
- ]
23
+ expect(described_class.diff).to eq(
24
+ actual_files: [
25
+ { file: './spec/fixtures/1_spec.rb:4', time: 1.4 },
26
+ { file: './spec/fixtures/1_spec.rb:6', time: 1.6 },
27
+ { file: './spec/fixtures/1_spec.rb:8', time: 1.8 },
28
+ { file: './spec/fixtures/2_spec.rb:4', time: 2.4 },
29
+ { file: './spec/fixtures/new_spec.rb:1', time: nil },
30
+ ],
31
+
32
+ actual_time: 7.2,
33
+ added_files: [{ file: './spec/fixtures/new_spec.rb:1', time: nil }],
34
+ added_time: '?',
35
+
36
+ removed_files: [
37
+ { file: './spec/fixtures/x_spec.rb:1', time: 3 },
38
+ { file: './spec/fixtures/2_spec.rb:666', time: 6 },
39
+ ],
40
+
41
+ removed_time: 9.0
42
+ )
30
43
  end
31
44
  end
32
45
 
33
46
  context 'when has duplicated example' do
34
47
  before do
35
- redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:4', time: '1.4' }.to_json)
36
- redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:4', time: '1.4' }.to_json)
48
+ redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:4', time: 1.4 }.to_json)
49
+ redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:4', time: 1.4 }.to_json)
37
50
  end
38
51
 
39
52
  it 'is removed' do
40
53
  EnvMock.mock(rspeed_spec_path: './spec/fixtures/*_spec.rb') do
41
- expect(described_class.diff).to eq [
42
- { file: './spec/fixtures/1_spec.rb:4', time: '1.4' },
43
- { file: './spec/fixtures/1_spec.rb:6', time: '1.6' },
44
- { file: './spec/fixtures/1_spec.rb:8', time: '1.8' },
45
- { file: './spec/fixtures/2_spec.rb:4', time: '2.4' },
46
- { file: './spec/fixtures/new_spec.rb:1', time: 0 },
47
- ]
54
+ expect(described_class.diff).to eq(
55
+ actual_files: [
56
+ { file: './spec/fixtures/1_spec.rb:4', time: 1.4 },
57
+ { file: './spec/fixtures/1_spec.rb:6', time: 1.6 },
58
+ { file: './spec/fixtures/1_spec.rb:8', time: 1.8 },
59
+ { file: './spec/fixtures/2_spec.rb:4', time: 2.4 },
60
+ { file: './spec/fixtures/new_spec.rb:1', time: nil },
61
+ ],
62
+
63
+ actual_time: 7.2,
64
+ added_files: [{ file: './spec/fixtures/new_spec.rb:1', time: nil }],
65
+ added_time: '?',
66
+
67
+ removed_files: [
68
+ { file: './spec/fixtures/x_spec.rb:1', time: 3 },
69
+ { file: './spec/fixtures/2_spec.rb:666', time: 6 },
70
+ ],
71
+
72
+ removed_time: 9.0
73
+ )
48
74
  end
49
75
  end
50
76
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'support/env_mock'
4
+
5
+ RSpec.describe RSpeed::Differ, '#final_diff' do
6
+ let!(:redis) { redis_object }
7
+
8
+ before do
9
+ redis.rpush('rspeed_previous', { file: './spec/fixtures/1_spec.rb:1', time: 1.1 }.to_json)
10
+ redis.rpush('rspeed_previous', { file: './spec/fixtures/2_spec.rb:2', time: 2.2 }.to_json)
11
+ redis.rpush('rspeed_previous', { file: './spec/fixtures/3_spec.rb:3', time: 3.3 }.to_json)
12
+ redis.rpush('rspeed_previous', { file: './spec/fixtures/4_spec.rb:4', time: 4.4 }.to_json)
13
+
14
+ redis.rpush('rspeed', { file: './spec/fixtures/1_spec.rb:1', time: 1.1 }.to_json)
15
+ redis.rpush('rspeed', { file: './spec/fixtures/2_spec.rb:2', time: 2.2 }.to_json)
16
+ redis.rpush('rspeed', { file: './spec/fixtures/5_spec.rb:5', time: 5.5 }.to_json)
17
+ redis.rpush('rspeed', { file: './spec/fixtures/6_spec.rb:6', time: 6.6 }.to_json)
18
+ end
19
+
20
+ it 'returns the diff' do
21
+ expect(described_class.final_diff).to eq(
22
+ actual_files: [
23
+ { file: './spec/fixtures/1_spec.rb:1', time: 1.1 },
24
+ { file: './spec/fixtures/2_spec.rb:2', time: 2.2 },
25
+ { file: './spec/fixtures/5_spec.rb:5', time: 5.5 },
26
+ { file: './spec/fixtures/6_spec.rb:6', time: 6.6 },
27
+ ],
28
+
29
+ actual_time: 15.4,
30
+
31
+ added_files: [
32
+ { file: './spec/fixtures/5_spec.rb:5', time: 5.5 },
33
+ { file: './spec/fixtures/6_spec.rb:6', time: 6.6 },
34
+ ],
35
+
36
+ added_time: 12.1,
37
+
38
+ removed_files: [
39
+ { file: './spec/fixtures/3_spec.rb:3', time: 3.3 },
40
+ { file: './spec/fixtures/4_spec.rb:4', time: 4.4 },
41
+ ],
42
+
43
+ removed_time: 7.7
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Differ, '#sum_time' do
4
+ context 'when has at least one time with value' do
5
+ let!(:data) { [{ time: 1.4 }, { time: 1.6 }, { time: 2.4 }, { time: nil }] }
6
+
7
+ it 'sums the time key' do
8
+ expect(described_class.sum_time(data: data)).to be(5.4)
9
+ end
10
+ end
11
+
12
+ context 'when all time are nil' do
13
+ let!(:data) { [{ time: nil }, { time: nil }] }
14
+
15
+ it 'returns a question mark' do
16
+ expect(described_class.sum_time(data: data)).to eq('?')
17
+ end
18
+ end
19
+ end
@@ -16,7 +16,9 @@ RSpec.describe RSpeed::Observer, '.after_suite' do
16
16
  context 'when all specs finished' do
17
17
  before do
18
18
  allow(RSpeed::Redis).to receive(:specs_finished?).and_return(true)
19
+ allow(RSpeed::Redis).to receive(:version_the_result)
19
20
  allow(RSpeed::Splitter).to receive(:consolidate)
21
+ allow(RSpeed::Reporter).to receive(:call)
20
22
  allow(RSpeed::Redis).to receive(:clean)
21
23
  end
22
24
 
@@ -26,6 +28,12 @@ RSpec.describe RSpeed::Observer, '.after_suite' do
26
28
  expect(RSpeed::Splitter).to have_received(:consolidate)
27
29
  end
28
30
 
31
+ it 'reports' do
32
+ described_class.after_suite
33
+
34
+ expect(RSpeed::Reporter).to have_received(:call)
35
+ end
36
+
29
37
  it 'destroyes pipe finished flag keys' do
30
38
  described_class.after_suite
31
39
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe RSpeed::Redis, '.specs_initiated?' do
3
+ RSpec.describe RSpeed::Redis, '.specs_finished?' do
4
4
  context 'when has no pipe flag key' do
5
5
  it { expect(described_class.specs_finished?).to be(false) }
6
6
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '.version_the_result' do
4
+ before { redis_object.rpush(RSpeed::Variable.result, true) }
5
+
6
+ it 'renames the result to a previous result key' do
7
+ described_class.version_the_result
8
+
9
+ expect(redis_object.keys).to eq([RSpeed::Variable.previous_result])
10
+ end
11
+
12
+ context 'when already have a previous result' do
13
+ before { redis_object.rpush(RSpeed::Variable.previous_result, true) }
14
+
15
+ it 'overrides' do
16
+ described_class.version_the_result
17
+
18
+ expect(redis_object.keys).to eq([RSpeed::Variable.previous_result])
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Reporter, '#call' do
4
+ let!(:previous_result) do
5
+ [
6
+ { file: './spec/fixtures/1_spec.rb:1', time: 1.1 },
7
+ { file: './spec/fixtures/2_spec.rb:2', time: 2.2 },
8
+ { file: './spec/fixtures/3_spec.rb:3', time: 3.3 },
9
+ { file: './spec/fixtures/4_spec.rb:4', time: 4.4 },
10
+ ]
11
+ end
12
+
13
+ let!(:result) do
14
+ [
15
+ { file: './spec/fixtures/1_spec.rb:1', time: 1.1 },
16
+ { file: './spec/fixtures/2_spec.rb:2', time: 2.2 },
17
+ { file: './spec/fixtures/5_spec.rb:5', time: 5.5 },
18
+ { file: './spec/fixtures/6_spec.rb:6', time: 6.6 },
19
+ ]
20
+ end
21
+
22
+ before do
23
+ allow(RSpeed::Database).to receive(:previous_result).and_return(previous_result)
24
+ allow(RSpeed::Database).to receive(:result).and_return(result)
25
+ end
26
+
27
+ it 'prints a report' do
28
+ output = <<~HEREDOC
29
+ +--------------+-------+
30
+ | RSpeed |
31
+ +--------------+-------+
32
+ | Global | Value |
33
+ +--------------+-------+
34
+ | Actual Time | 15.4 |
35
+ | Removed Time | 7.7 |
36
+ | Added Time | 12.1 |
37
+ +--------------+-------+
38
+ HEREDOC
39
+
40
+ expect { described_class.call }.to output(output).to_stdout
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Reporter, '#print_files' do
4
+ let!(:items) do
5
+ [
6
+ { file: './spec/fixtures/1_spec.rb:1', time: 1.1 },
7
+ { file: './spec/fixtures/2_spec.rb:2', time: 2.2 },
8
+ { file: './spec/fixtures/3_spec.rb:3', time: 3.3 },
9
+ ]
10
+ end
11
+
12
+ it 'prints the attributes' do
13
+ output = <<~HEREDOC
14
+ +---------+-----------------------------+-----------+
15
+ | RSpeed |
16
+ +---------+-----------------------------+-----------+
17
+ | 3 specs | Pipe 1/1 | Last Time |
18
+ +---------+-----------------------------+-----------+
19
+ | 01 | ./spec/fixtures/1_spec.rb:1 | 1.1 |
20
+ | 02 | ./spec/fixtures/2_spec.rb:2 | 2.2 |
21
+ | 03 | ./spec/fixtures/3_spec.rb:3 | 3.3 |
22
+ +---------+-----------------------------+-----------+
23
+ HEREDOC
24
+
25
+ expect { described_class.print_files(items) }.to output(output).to_stdout
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Reporter, '#print_table' do
4
+ let!(:headings) { %w[Global Value] }
5
+
6
+ let!(:rows) do
7
+ [
8
+ ['Actual Time', 1.0],
9
+ ['Removed Time', 2.0],
10
+ ['Added Time', 3.0],
11
+ ]
12
+ end
13
+
14
+ it 'prints' do
15
+ output = <<~HEREDOC
16
+ +--------------+-------+
17
+ | RSpeed |
18
+ +--------------+-------+
19
+ | Global | Value |
20
+ +--------------+-------+
21
+ | Actual Time | 1.0 |
22
+ | Removed Time | 2.0 |
23
+ | Added Time | 3.0 |
24
+ +--------------+-------+
25
+ HEREDOC
26
+
27
+ expect { described_class.print_table(headings: headings, rows: rows) }.to output(output).to_stdout
28
+ end
29
+ end
@@ -10,12 +10,21 @@ RSpec.describe RSpeed::Splitter, '#pipe_files' do
10
10
  context 'when has result' do
11
11
  before do
12
12
  allow(RSpeed::Redis).to receive(:result?).and_return(true)
13
+ allow(RSpeed::Reporter).to receive(:print_files)
13
14
 
14
- allow(described_class).to receive(:split).and_return(rspeed_1: { files: [{ file: 'spec_1.rb' }, { file: 'spec_2.rb' }] })
15
+ allow(described_class).to receive(:split)
16
+ .and_return(rspeed_1: { files: [{ file: 'spec_1.rb', time: 1.0 }, { file: 'spec_2.rb', time: 2.0 }] })
15
17
  end
16
18
 
17
19
  it 'returns the splitted pipe files' do
18
20
  expect(described_class.pipe_files).to eq('spec_1.rb spec_2.rb')
19
21
  end
22
+
23
+ it 'prints the files' do
24
+ described_class.pipe_files
25
+
26
+ expect(RSpeed::Reporter).to have_received(:print_files)
27
+ .with([{ file: 'spec_1.rb', time: 1.0 }, { file: 'spec_2.rb', time: 2.0 }])
28
+ end
20
29
  end
21
30
  end
@@ -3,49 +3,91 @@
3
3
  require 'support/env_mock'
4
4
 
5
5
  RSpec.describe RSpeed::Splitter, '.split' do
6
- let!(:unsorted_data) do
7
- [
8
- { file: './spec/1_5_spec.rb', time: '1.5' },
9
- { file: './spec/1_1_spec.rb', time: '1.1' },
10
- { file: './spec/0_7_spec.rb', time: '0.7' },
11
- { file: './spec/0_4_spec.rb', time: '0.4' },
12
- { file: './spec/0_3_spec.rb', time: '0.3' },
13
- { file: './spec/0_2_spec.rb', time: '0.2' },
14
- { file: './spec/2_0_spec.rb', time: '2.0' },
15
- ]
6
+ context 'when has no nil time' do
7
+ let!(:unsorted_data) do
8
+ [
9
+ { file: './spec/1_5_spec.rb', time: 1.5 },
10
+ { file: './spec/1_1_spec.rb', time: 1.1 },
11
+ { file: './spec/0_7_spec.rb', time: 0.7 },
12
+ { file: './spec/0_4_spec.rb', time: 0.4 },
13
+ { file: './spec/0_3_spec.rb', time: 0.3 },
14
+ { file: './spec/0_2_spec.rb', time: 0.2 },
15
+ { file: './spec/2_0_spec.rb', time: 2.0 },
16
+ ]
17
+ end
18
+
19
+ it 'splits the times between the pipes' do
20
+ EnvMock.mock(rspeed_pipes: 3) do
21
+ expect(described_class.split(data: unsorted_data)).to eq(
22
+ rspeed_1: {
23
+ files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
24
+ number: 1,
25
+ total: 2.0,
26
+ },
27
+
28
+ rspeed_2: {
29
+ files: [
30
+ { file: './spec/1_5_spec.rb', time: 1.5 },
31
+ { file: './spec/0_4_spec.rb', time: 0.4 },
32
+ { file: './spec/0_2_spec.rb', time: 0.2 },
33
+ ],
34
+
35
+ number: 2,
36
+ total: 1.5 + 0.4 + 0.2, # 1.5 -> 1.9 -> 2.1
37
+ },
38
+
39
+ rspeed_3: {
40
+ files: [
41
+ { file: './spec/1_1_spec.rb', time: 1.1 },
42
+ { file: './spec/0_7_spec.rb', time: 0.7 },
43
+ { file: './spec/0_3_spec.rb', time: 0.3 },
44
+ ],
45
+
46
+ number: 3,
47
+ total: 1.1 + 0.7 + 0.3, # 1.1 -> 1.8 -> 2.1
48
+ }
49
+ )
50
+ end
51
+ end
16
52
  end
17
53
 
18
- it 'splits the times between the pipes' do
19
- EnvMock.mock(rspeed_pipes: 3) do
20
- expect(described_class.split(data: unsorted_data)).to eq(
21
- rspeed_1: {
22
- files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
23
- number: 1,
24
- total: 2.0,
25
- },
26
-
27
- rspeed_2: {
28
- files: [
29
- { file: './spec/1_5_spec.rb', time: 1.5 },
30
- { file: './spec/0_4_spec.rb', time: 0.4 },
31
- { file: './spec/0_2_spec.rb', time: 0.2 },
32
- ],
33
-
34
- number: 2,
35
- total: 1.5 + 0.4 + 0.2, # 1.5 -> 1.9 -> 2.1
36
- },
37
-
38
- rspeed_3: {
39
- files: [
40
- { file: './spec/1_1_spec.rb', time: 1.1 },
41
- { file: './spec/0_7_spec.rb', time: 0.7 },
42
- { file: './spec/0_3_spec.rb', time: 0.3 },
43
- ],
44
-
45
- number: 3,
46
- total: 1.1 + 0.7 + 0.3, # 1.1 -> 1.8 -> 2.1
47
- }
48
- )
54
+ context 'when has nil time' do
55
+ let!(:unsorted_data) do
56
+ [
57
+ { file: './spec/1_5_spec.rb', time: 1.5 },
58
+ { file: './spec/1_1_spec.rb', time: 1.1 },
59
+ { file: './spec/2_0_spec.rb', time: nil },
60
+ ]
61
+ end
62
+
63
+ it 'uses zero as default' do
64
+ EnvMock.mock(rspeed_pipes: 3) do
65
+ expect(described_class.split(data: unsorted_data)).to eq(
66
+ rspeed_1: {
67
+ files: [{ file: './spec/1_5_spec.rb', time: 1.5 }],
68
+ number: 1,
69
+ total: 1.5,
70
+ },
71
+
72
+ rspeed_2: {
73
+ files: [
74
+ { file: './spec/1_1_spec.rb', time: 1.1 },
75
+ ],
76
+
77
+ number: 2,
78
+ total: 1.1
79
+ },
80
+
81
+ rspeed_3: {
82
+ files: [
83
+ { file: './spec/2_0_spec.rb', time: 0.0 },
84
+ ],
85
+
86
+ number: 3,
87
+ total: 0.0,
88
+ }
89
+ )
90
+ end
49
91
  end
50
92
  end
51
93
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'support/env_mock'
4
+
5
+ RSpec.describe RSpeed::Variable, '.previous_result' do
6
+ it { expect(described_class.previous_result).to eq('rspeed_previous') }
7
+
8
+ context 'when env app is given' do
9
+ it 'includes the app' do
10
+ EnvMock.mock(rspeed_app: 'app') do
11
+ expect(described_class.previous_result).to eq('rspeed_app_previous')
12
+ end
13
+ end
14
+ end
15
+
16
+ context 'when env app is not given' do
17
+ it { expect(described_class.previous_result).to eq('rspeed_previous') }
18
+ end
19
+ end
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.6.0
4
+ version: 0.7.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: 2021-02-07 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: codecov
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +186,7 @@ files:
172
186
  - lib/rspeed/logger.rb
173
187
  - lib/rspeed/observer.rb
174
188
  - lib/rspeed/redis.rb
189
+ - lib/rspeed/reporter.rb
175
190
  - lib/rspeed/runner.rb
176
191
  - lib/rspeed/splitter.rb
177
192
  - lib/rspeed/variable.rb
@@ -180,13 +195,16 @@ files:
180
195
  - spec/fixtures/1_spec.rb
181
196
  - spec/fixtures/2_spec.rb
182
197
  - spec/fixtures/empty.rb
198
+ - spec/models/rspeed/database/list_spec.rb
199
+ - spec/models/rspeed/database/previous_result_spec.rb
183
200
  - spec/models/rspeed/database/result_spec.rb
184
201
  - spec/models/rspeed/differ/actual_data_spec.rb
185
202
  - spec/models/rspeed/differ/actual_files_spec.rb
186
203
  - spec/models/rspeed/differ/added_data_spec.rb
187
204
  - spec/models/rspeed/differ/diff_spec.rb
205
+ - spec/models/rspeed/differ/final_diff_spec.rb
188
206
  - spec/models/rspeed/differ/removed_data_spec.rb
189
- - spec/models/rspeed/differ/removed_time_spec.rb
207
+ - spec/models/rspeed/differ/sum_time_spec.rb
190
208
  - spec/models/rspeed/env/app_spec.rb
191
209
  - spec/models/rspeed/env/db_spec.rb
192
210
  - spec/models/rspeed/env/host_spec.rb
@@ -210,6 +228,10 @@ files:
210
228
  - spec/models/rspeed/redis/set_spec.rb
211
229
  - spec/models/rspeed/redis/specs_finished_spec.rb
212
230
  - spec/models/rspeed/redis/specs_initiated_spec.rb
231
+ - spec/models/rspeed/redis/version_the_result_spec.rb
232
+ - spec/models/rspeed/reporter/call_spec.rb
233
+ - spec/models/rspeed/reporter/print_files_spec.rb
234
+ - spec/models/rspeed/reporter/print_table_spec.rb
213
235
  - spec/models/rspeed/runner/run_spec.rb
214
236
  - spec/models/rspeed/splitter/append_spec.rb
215
237
  - spec/models/rspeed/splitter/consolidate_spec.rb
@@ -221,6 +243,7 @@ files:
221
243
  - spec/models/rspeed/variable/key_spec.rb
222
244
  - spec/models/rspeed/variable/pipe_spec.rb
223
245
  - spec/models/rspeed/variable/pipes_pattern_spec.rb
246
+ - spec/models/rspeed/variable/previous_result_spec.rb
224
247
  - spec/models/rspeed/variable/profile_pattern_spec.rb
225
248
  - spec/models/rspeed/variable/profile_spec.rb
226
249
  - spec/models/rspeed/variable/result_spec.rb
@@ -254,11 +277,14 @@ specification_version: 4
254
277
  summary: Split and speed up your RSpec tests.
255
278
  test_files:
256
279
  - spec/spec_helper.rb
280
+ - spec/models/rspeed/database/list_spec.rb
257
281
  - spec/models/rspeed/database/result_spec.rb
282
+ - spec/models/rspeed/database/previous_result_spec.rb
258
283
  - spec/models/rspeed/variable/pipes_pattern_spec.rb
259
284
  - spec/models/rspeed/variable/pipe_spec.rb
260
285
  - spec/models/rspeed/variable/result_spec.rb
261
286
  - spec/models/rspeed/variable/key_spec.rb
287
+ - spec/models/rspeed/variable/previous_result_spec.rb
262
288
  - spec/models/rspeed/variable/profile_pattern_spec.rb
263
289
  - spec/models/rspeed/variable/profile_spec.rb
264
290
  - spec/models/rspeed/variable/append_app_name_spec.rb
@@ -267,12 +293,16 @@ test_files:
267
293
  - spec/models/rspeed/redis/clean_spec.rb
268
294
  - spec/models/rspeed/redis/client_spec.rb
269
295
  - spec/models/rspeed/redis/specs_finished_spec.rb
296
+ - spec/models/rspeed/redis/version_the_result_spec.rb
270
297
  - spec/models/rspeed/redis/list_spec.rb
271
298
  - spec/models/rspeed/redis/set_spec.rb
272
299
  - spec/models/rspeed/redis/specs_initiated_spec.rb
273
300
  - spec/models/rspeed/redis/result_spec.rb
274
301
  - spec/models/rspeed/redis/keys_spec.rb
275
302
  - spec/models/rspeed/redis/profiles_content_spec.rb
303
+ - spec/models/rspeed/reporter/print_files_spec.rb
304
+ - spec/models/rspeed/reporter/call_spec.rb
305
+ - spec/models/rspeed/reporter/print_table_spec.rb
276
306
  - spec/models/rspeed/runner/run_spec.rb
277
307
  - spec/models/rspeed/splitter/append_spec.rb
278
308
  - spec/models/rspeed/splitter/need_warm_question_spec.rb
@@ -284,11 +314,12 @@ test_files:
284
314
  - spec/models/rspeed/observer/before_spec.rb
285
315
  - spec/models/rspeed/observer/after_suite_spec.rb
286
316
  - spec/models/rspeed/observer/after_spec.rb
317
+ - spec/models/rspeed/differ/final_diff_spec.rb
287
318
  - spec/models/rspeed/differ/actual_files_spec.rb
288
319
  - spec/models/rspeed/differ/removed_data_spec.rb
289
320
  - spec/models/rspeed/differ/actual_data_spec.rb
290
321
  - spec/models/rspeed/differ/diff_spec.rb
291
- - spec/models/rspeed/differ/removed_time_spec.rb
322
+ - spec/models/rspeed/differ/sum_time_spec.rb
292
323
  - spec/models/rspeed/differ/added_data_spec.rb
293
324
  - spec/models/rspeed/env/pipe_spec.rb
294
325
  - spec/models/rspeed/env/spec_path_spec.rb
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RSpeed::Differ, '#removed_time' do
4
- let!(:data) do
5
- [
6
- { file: './spec/fixtures/1_spec.rb:4', time: 1.4 },
7
- { file: './spec/fixtures/1_spec.rb:6', time: 1.6 },
8
- ]
9
- end
10
-
11
- it 'returns the sum of removed examples' do
12
- expect(described_class.removed_time(data: data)).to be(3.0)
13
- end
14
- end