rspeed 0.5.2 → 0.6.0

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +3 -3
  4. data/lib/rspeed.rb +1 -0
  5. data/lib/rspeed/database.rb +11 -0
  6. data/lib/rspeed/differ.rb +55 -0
  7. data/lib/rspeed/env.rb +8 -8
  8. data/lib/rspeed/logger.rb +4 -2
  9. data/lib/rspeed/observer.rb +8 -8
  10. data/lib/rspeed/redis.rb +20 -12
  11. data/lib/rspeed/runner.rb +4 -4
  12. data/lib/rspeed/splitter.rb +12 -85
  13. data/lib/rspeed/variable.rb +9 -10
  14. data/lib/rspeed/version.rb +1 -1
  15. data/spec/models/rspeed/database/result_spec.rb +17 -0
  16. data/spec/models/rspeed/differ/actual_data_spec.rb +20 -0
  17. data/spec/models/rspeed/differ/actual_files_spec.rb +20 -0
  18. data/spec/models/rspeed/differ/added_data_spec.rb +19 -0
  19. data/spec/models/rspeed/differ/diff_spec.rb +51 -0
  20. data/spec/models/rspeed/differ/removed_data_spec.rb +20 -0
  21. data/spec/models/rspeed/differ/removed_time_spec.rb +14 -0
  22. data/spec/models/rspeed/env/{name_spec.rb → app_spec.rb} +4 -4
  23. data/spec/models/rspeed/env/spec_path_spec.rb +19 -0
  24. data/spec/models/rspeed/observer/after_suite_spec.rb +6 -28
  25. data/spec/models/rspeed/observer/before_suite_spec.rb +7 -6
  26. data/spec/models/rspeed/redis/clean_spec.rb +5 -5
  27. data/spec/models/rspeed/redis/destroy_spec.rb +7 -15
  28. data/spec/models/rspeed/redis/get_spec.rb +3 -1
  29. data/spec/models/rspeed/redis/keys_spec.rb +6 -22
  30. data/spec/models/rspeed/redis/list_spec.rb +19 -0
  31. data/spec/models/rspeed/redis/profiles_content_spec.rb +19 -0
  32. data/spec/models/rspeed/redis/set_spec.rb +3 -1
  33. data/spec/models/rspeed/redis/specs_finished_spec.rb +2 -2
  34. data/spec/models/rspeed/redis/specs_initiated_spec.rb +1 -1
  35. data/spec/models/rspeed/runner/run_spec.rb +9 -13
  36. data/spec/models/rspeed/splitter/append_spec.rb +1 -3
  37. data/spec/models/rspeed/splitter/consolidate_spec.rb +23 -0
  38. data/spec/models/rspeed/splitter/first_pipe_spec.rb +2 -4
  39. data/spec/models/rspeed/splitter/need_warm_question_spec.rb +8 -10
  40. data/spec/models/rspeed/splitter/pipe_files_spec.rb +3 -8
  41. data/spec/models/rspeed/splitter/split_spec.rb +5 -43
  42. data/spec/models/rspeed/variable/append_app_name_spec.rb +33 -0
  43. data/spec/models/rspeed/variable/key_spec.rb +4 -4
  44. data/spec/models/rspeed/variable/pipe_spec.rb +23 -0
  45. data/spec/models/rspeed/variable/pipes_pattern_spec.rb +1 -1
  46. data/spec/models/rspeed/variable/profile_pattern_spec.rb +1 -1
  47. data/spec/models/rspeed/variable/profile_spec.rb +23 -0
  48. data/spec/models/rspeed/variable/result_spec.rb +5 -5
  49. data/spec/spec_helper.rb +2 -2
  50. metadata +33 -25
  51. data/spec/fixtures/new_spec.rb.csv +0 -1
  52. data/spec/models/rspeed/env/result_key_spec.rb +0 -19
  53. data/spec/models/rspeed/splitter/actual_examples_spec.rb +0 -26
  54. data/spec/models/rspeed/splitter/append_question_spec.rb +0 -37
  55. data/spec/models/rspeed/splitter/diff_spec.rb +0 -30
  56. data/spec/models/rspeed/splitter/get_spec.rb +0 -60
  57. data/spec/models/rspeed/splitter/rename_spec.rb +0 -25
  58. data/spec/models/rspeed/variable/append_name_spec.rb +0 -19
  59. data/spec/models/rspeed/variable/default_partner_spec.rb +0 -5
  60. data/spec/models/rspeed/variable/pipe_name_spec.rb +0 -15
  61. data/spec/models/rspeed/variable/pipe_profile_spec.rb +0 -15
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '#list' do
4
+ let!(:redis) { redis_object }
5
+
6
+ before do
7
+ redis.rpush('key', { file: '1_spec.rb', time: 1.0 }.to_json)
8
+ redis.rpush('key', { file: '2_spec.rb', time: 2.0 }.to_json)
9
+ redis.rpush('key', { file: '3_spec.rb', time: 3.0 }.to_json)
10
+ end
11
+
12
+ it 'list all key entries' do
13
+ expect(described_class.list('key')).to eq [
14
+ '{"file":"1_spec.rb","time":1.0}',
15
+ '{"file":"2_spec.rb","time":2.0}',
16
+ '{"file":"3_spec.rb","time":3.0}',
17
+ ]
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '#profiles_content' do
4
+ let!(:redis) { redis_object }
5
+
6
+ before do
7
+ redis.rpush('rspeed:profile_01', { file: '1_spec.rb', time: 1.0 }.to_json)
8
+ redis.rpush('rspeed:profile_02', { file: '2_spec.rb', time: 2.0 }.to_json)
9
+ redis.rpush('rspeed:profile_03', { file: '3_spec.rb', time: 3.0 }.to_json)
10
+ end
11
+
12
+ it 'returns the content of all profiles keys' do
13
+ expect(described_class.profiles_content).to eq [
14
+ '{"file":"1_spec.rb","time":1.0}',
15
+ '{"file":"2_spec.rb","time":2.0}',
16
+ '{"file":"3_spec.rb","time":3.0}',
17
+ ]
18
+ end
19
+ end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Redis, '.set' do
4
+ let!(:redis) { redis_object }
5
+
4
6
  it 'sets a key on redis' do
5
7
  described_class.set('key', 'value')
6
8
 
7
- expect(described_class.client.get('key')).to eq('value')
9
+ expect(redis.get('key')).to eq('value')
8
10
  end
9
11
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  RSpec.describe RSpeed::Redis, '.specs_finished?' do
4
4
  before do
5
- described_class.set('rspeed_pipe_1', '1.0')
5
+ described_class.set('rspeed:pipe_01', '1.0')
6
6
 
7
7
  allow(RSpeed::Env).to receive(:pipes).and_return(2)
8
8
  end
@@ -12,7 +12,7 @@ RSpec.describe RSpeed::Redis, '.specs_finished?' do
12
12
  end
13
13
 
14
14
  context 'when the quantity of pipe result is the same as the quantity of pipes' do
15
- before { described_class.set('rspeed_pipe_2', '2.0') }
15
+ before { described_class.set('rspeed:pipe_02', '2.0') }
16
16
 
17
17
  it { expect(described_class.specs_finished?).to be(true) }
18
18
  end
@@ -6,7 +6,7 @@ RSpec.describe RSpeed::Redis, '.specs_initiated?' do
6
6
  end
7
7
 
8
8
  context 'when has at least one pipe flag key' do
9
- before { described_class.set('rspeed_pipe_1', '1.0') }
9
+ before { described_class.set('rspeed:pipe_01', '1.0') }
10
10
 
11
11
  it { expect(described_class.specs_finished?).to be(true) }
12
12
  end
@@ -2,20 +2,16 @@
2
2
 
3
3
  RSpec.describe RSpeed::Runner, '#run' do
4
4
  let!(:shell) { double('shell') }
5
- let!(:splitter) { instance_double('RSpeed::Splitter') }
6
5
 
7
- before do
8
- allow(shell).to receive(:call)
9
- allow(RSpeed::Splitter).to receive(:new).and_return(splitter)
10
- end
6
+ before { allow(shell).to receive(:call) }
11
7
 
12
8
  context 'when has result' do
13
9
  before { allow(RSpeed::Redis).to receive(:result?).and_return(true) }
14
10
 
15
11
  context 'when is the first pipe' do
16
12
  before do
17
- allow(splitter).to receive(:first_pipe?).and_return(true)
18
- allow(splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
13
+ allow(RSpeed::Splitter).to receive(:first_pipe?).and_return(true)
14
+ allow(RSpeed::Splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
19
15
  end
20
16
 
21
17
  it 'runs the pipe specs' do
@@ -27,8 +23,8 @@ RSpec.describe RSpeed::Runner, '#run' do
27
23
 
28
24
  context 'when is not the first pipe' do
29
25
  before do
30
- allow(splitter).to receive(:first_pipe?).and_return(false)
31
- allow(splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
26
+ allow(RSpeed::Splitter).to receive(:first_pipe?).and_return(false)
27
+ allow(RSpeed::Splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
32
28
  end
33
29
 
34
30
  it 'runs the pipe specs' do
@@ -41,12 +37,12 @@ RSpec.describe RSpeed::Runner, '#run' do
41
37
 
42
38
  context 'when has no result' do
43
39
  before do
44
- allow(splitter).to receive(:first_pipe?).and_return(false)
45
- allow(splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
40
+ allow(RSpeed::Splitter).to receive(:first_pipe?).and_return(false)
41
+ allow(RSpeed::Splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
46
42
  end
47
43
 
48
44
  context 'when is the first pipe' do
49
- before { allow(splitter).to receive(:first_pipe?).and_return(true) }
45
+ before { allow(RSpeed::Splitter).to receive(:first_pipe?).and_return(true) }
50
46
 
51
47
  it 'runs the pipe specs' do
52
48
  described_class.run(shell)
@@ -57,7 +53,7 @@ RSpec.describe RSpeed::Runner, '#run' do
57
53
 
58
54
  context 'when is not the first pipe' do
59
55
  before do
60
- allow(splitter).to receive(:first_pipe?).and_return(false)
56
+ allow(RSpeed::Splitter).to receive(:first_pipe?).and_return(false)
61
57
  allow(RSpeed::Observer).to receive(:after_suite)
62
58
  end
63
59
 
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Splitter, '#append' do
4
- subject(:splitter) { described_class.new }
5
-
6
4
  let!(:redis) { redis_object }
7
5
 
8
6
  it 'appends file and time on rspeed key' do
9
- splitter.append(
7
+ described_class.append(
10
8
  items: [{ file: '1_spec.rb', time: 1 }.to_json, { file: '2_spec.rb', time: 2 }.to_json],
11
9
  key: 'rspeed'
12
10
  )
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Splitter, '#consolidate' do
4
+ let!(:redis) { redis_object }
5
+
6
+ before do
7
+ redis.rpush('rspeed', 'rspeed_content')
8
+
9
+ redis.rpush('rspeed:profile_01', { file: '1_spec.rb', time: 1.0 }.to_json)
10
+ redis.rpush('rspeed:profile_02', { file: '2_spec.rb', time: 2.0 }.to_json)
11
+ redis.rpush('rspeed:profile_03', { file: '3_spec.rb', time: 3.0 }.to_json)
12
+ end
13
+
14
+ it 'copies profiles to the result key cleanning the previous result' do
15
+ described_class.consolidate
16
+
17
+ expect(redis.lrange('rspeed', 0, -1)).to eq [
18
+ '{"file":"1_spec.rb","time":1.0}',
19
+ '{"file":"2_spec.rb","time":2.0}',
20
+ '{"file":"3_spec.rb","time":3.0}',
21
+ ]
22
+ end
23
+ end
@@ -1,17 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Splitter, '.first_pipe?' do
4
- subject(:splitter) { described_class.new }
5
-
6
4
  context 'when pipe env is 1' do
7
5
  before { allow(RSpeed::Env).to receive(:pipe).and_return 1 }
8
6
 
9
- it { expect(splitter.first_pipe?).to eq true }
7
+ it { expect(described_class.first_pipe?).to eq true }
10
8
  end
11
9
 
12
10
  context 'when pipe env is not 1' do
13
11
  before { allow(RSpeed::Env).to receive(:pipe).and_return 2 }
14
12
 
15
- it { expect(splitter.first_pipe?).to eq false }
13
+ it { expect(described_class.first_pipe?).to eq false }
16
14
  end
17
15
  end
@@ -1,21 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Splitter, '#need_warm?' do
4
- subject(:splitter) { described_class.new }
5
-
6
4
  context 'when has no result' do
7
5
  before { allow(RSpeed::Redis).to receive(:result?).and_return(false) }
8
6
 
9
7
  context 'when is not the first pipe' do
10
- before { allow(splitter).to receive(:first_pipe?).and_return(false) }
8
+ before { allow(described_class).to receive(:first_pipe?).and_return(false) }
11
9
 
12
- it { expect(splitter.need_warm?).to be(false) }
10
+ it { expect(described_class.need_warm?).to be(false) }
13
11
  end
14
12
 
15
13
  context 'when is the first pipe' do
16
- before { allow(splitter).to receive(:first_pipe?).and_return(true) }
14
+ before { allow(described_class).to receive(:first_pipe?).and_return(true) }
17
15
 
18
- it { expect(splitter.need_warm?).to be(true) }
16
+ it { expect(described_class.need_warm?).to be(true) }
19
17
  end
20
18
  end
21
19
 
@@ -23,15 +21,15 @@ RSpec.describe RSpeed::Splitter, '#need_warm?' do
23
21
  before { allow(RSpeed::Redis).to receive(:result?).and_return(true) }
24
22
 
25
23
  context 'when is not the first pipe' do
26
- before { allow(splitter).to receive(:first_pipe?).and_return(false) }
24
+ before { allow(described_class).to receive(:first_pipe?).and_return(false) }
27
25
 
28
- it { expect(splitter.need_warm?).to be(false) }
26
+ it { expect(described_class.need_warm?).to be(false) }
29
27
  end
30
28
 
31
29
  context 'when is the first pipe' do
32
- before { allow(splitter).to receive(:first_pipe?).and_return(true) }
30
+ before { allow(described_class).to receive(:first_pipe?).and_return(true) }
33
31
 
34
- it { expect(splitter.need_warm?).to be(false) }
32
+ it { expect(described_class.need_warm?).to be(false) }
35
33
  end
36
34
  end
37
35
  end
@@ -1,26 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Splitter, '#pipe_files' do
4
- let!(:shell) { double('shell') }
5
- let!(:splitter) { described_class.new }
6
-
7
- before { allow(RSpeed::Env).to receive(:pipe).and_return(1) }
8
-
9
4
  context 'when has no result' do
10
5
  before { allow(RSpeed::Redis).to receive(:result?).and_return(false) }
11
6
 
12
- it { expect(splitter.pipe_files).to be(nil) }
7
+ it { expect(described_class.pipe_files).to be(nil) }
13
8
  end
14
9
 
15
10
  context 'when has result' do
16
11
  before do
17
12
  allow(RSpeed::Redis).to receive(:result?).and_return(true)
18
13
 
19
- allow(splitter).to receive(:split).and_return(rspeed_1: { files: [{ file: 'spec_1.rb' }, { file: 'spec_2.rb' }] })
14
+ allow(described_class).to receive(:split).and_return(rspeed_1: { files: [{ file: 'spec_1.rb' }, { file: 'spec_2.rb' }] })
20
15
  end
21
16
 
22
17
  it 'returns the splitted pipe files' do
23
- expect(splitter.pipe_files).to eq 'spec_1.rb spec_2.rb'
18
+ expect(described_class.pipe_files).to eq('spec_1.rb spec_2.rb')
24
19
  end
25
20
  end
26
21
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe RSpeed::Splitter, '.split' do
4
- subject(:splitter) { described_class.new }
3
+ require 'support/env_mock'
5
4
 
5
+ RSpec.describe RSpeed::Splitter, '.split' do
6
6
  let!(:unsorted_data) do
7
7
  [
8
8
  { file: './spec/1_5_spec.rb', time: '1.5' },
@@ -15,47 +15,9 @@ RSpec.describe RSpeed::Splitter, '.split' do
15
15
  ]
16
16
  end
17
17
 
18
- before { allow(RSpeed::Env).to receive(:pipes).and_return 3 }
19
-
20
- context 'when diff is given' do
21
- it 'splits the times between the pipes' do
22
- expect(splitter.split(unsorted_data)).to eq(
23
- rspeed_1: {
24
- files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
25
- number: 1,
26
- total: 2.0,
27
- },
28
-
29
- rspeed_2: {
30
- files: [
31
- { file: './spec/1_5_spec.rb', time: 1.5 },
32
- { file: './spec/0_4_spec.rb', time: 0.4 },
33
- { file: './spec/0_2_spec.rb', time: 0.2 },
34
- ],
35
-
36
- number: 2,
37
- total: 1.5 + 0.4 + 0.2, # 1.5 -> 1.9 -> 2.1
38
- },
39
-
40
- rspeed_3: {
41
- files: [
42
- { file: './spec/1_1_spec.rb', time: 1.1 },
43
- { file: './spec/0_7_spec.rb', time: 0.7 },
44
- { file: './spec/0_3_spec.rb', time: 0.3 },
45
- ],
46
-
47
- number: 3,
48
- total: 1.1 + 0.7 + 0.3, # 1.1 -> 1.8 -> 2.1
49
- }
50
- )
51
- end
52
- end
53
-
54
- context 'when diff is not given' do
55
- before { allow(splitter).to receive(:diff).and_return(unsorted_data) }
56
-
57
- it 'splits the diff result into times between the pipes' do
58
- expect(splitter.split).to eq(
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(
59
21
  rspeed_1: {
60
22
  files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
61
23
  number: 1,
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'support/env_mock'
4
+
5
+ RSpec.describe RSpeed::Variable, '.append_app_name' do
6
+ context 'when env app is given' do
7
+ it 'appends the rspeed app name on the given value' do
8
+ EnvMock.mock(rspeed_app: 'app') do
9
+ expect(described_class.append_app_name('value')).to eq('value_app')
10
+ end
11
+ end
12
+
13
+ context 'when a plus is given' do
14
+ it 'appends the rspeed app name on the given value with the plus value' do
15
+ EnvMock.mock(rspeed_app: 'app', plus: 'plus') do
16
+ expect(described_class.append_app_name('value', plus: 'plus')).to eq('value_app_plus')
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ context 'when env app is not given' do
23
+ it 'uses just the given string' do
24
+ expect(described_class.append_app_name('value')).to eq('value')
25
+ end
26
+
27
+ context 'when a plus is given' do
28
+ it 'appends the plus value' do
29
+ expect(described_class.append_app_name('value', plus: 'plus')).to eq('value_plus')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -5,10 +5,10 @@ require 'support/env_mock'
5
5
  RSpec.describe RSpeed::Variable, '.key' do
6
6
  it { expect(described_class.key(1)).to be(:rspeed_1) }
7
7
 
8
- context 'when env name is given' do
9
- it 'includes the name' do
10
- EnvMock.mock(rspeed_name: 'name') do
11
- expect(described_class.key(1)).to be(:rspeed_name_1)
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.key(1)).to be(:rspeed_app_1)
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'support/env_mock'
4
+
5
+ RSpec.describe RSpeed::Variable, '.pipe' do
6
+ it { expect(described_class.pipe).to eq('rspeed:pipe_01') }
7
+
8
+ context 'when env name is given' do
9
+ it 'includes the name' do
10
+ EnvMock.mock(rspeed_app: 'app') do
11
+ expect(described_class.pipe).to eq('rspeed:pipe_app_01')
12
+ end
13
+ end
14
+ end
15
+
16
+ context 'when pipe is bigger than 9' do
17
+ it 'does not prefix zero on the number' do
18
+ EnvMock.mock(rspeed_pipe: 10) do
19
+ expect(described_class.pipe).to eq('rspeed:pipe_10')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Variable, 'PIPES_PATTERN' do
4
- it { expect(described_class::PIPES_PATTERN).to eq('rspeed_pipe_*') }
4
+ it { expect(described_class::PIPES_PATTERN).to eq('rspeed:pipe_*') }
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RSpeed::Variable, 'PROFILE_PATTERN' do
4
- it { expect(described_class::PROFILE_PATTERN).to eq('rspeed_profile_*') }
4
+ it { expect(described_class::PROFILE_PATTERN).to eq('rspeed:profile_*') }
5
5
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'support/env_mock'
4
+
5
+ RSpec.describe RSpeed::Variable, '.profile' do
6
+ it { expect(described_class.profile).to eq('rspeed:profile_01') }
7
+
8
+ context 'when env name is given' do
9
+ it 'includes the name' do
10
+ EnvMock.mock(rspeed_app: 'name') do
11
+ expect(described_class.profile).to eq('rspeed:profile_name_01')
12
+ end
13
+ end
14
+ end
15
+
16
+ context 'when pipe is bigger than 9' do
17
+ it 'does not prefix zero on the number' do
18
+ EnvMock.mock(rspeed_pipe: 10) do
19
+ expect(described_class.profile).to eq('rspeed:profile_10')
20
+ end
21
+ end
22
+ end
23
+ end