rspeed 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +11 -7
  4. data/lib/generators/rspeed/install_generator.rb +1 -1
  5. data/lib/rspeed.rb +8 -6
  6. data/lib/rspeed/env.rb +43 -0
  7. data/lib/rspeed/extension.rb +3 -2
  8. data/lib/rspeed/observer.rb +17 -3
  9. data/lib/rspeed/redis.rb +55 -0
  10. data/lib/rspeed/runner.rb +3 -18
  11. data/lib/rspeed/splitter.rb +29 -52
  12. data/lib/rspeed/variable.rb +31 -0
  13. data/lib/rspeed/version.rb +1 -1
  14. data/spec/common_helper.rb +10 -0
  15. data/spec/fixtures/empty.rb +4 -0
  16. data/spec/models/rspeed/env/db_spec.rb +17 -0
  17. data/spec/models/rspeed/env/host_spec.rb +17 -0
  18. data/spec/models/rspeed/env/name_spec.rb +17 -0
  19. data/spec/models/rspeed/env/pipe_spec.rb +19 -0
  20. data/spec/models/rspeed/env/pipes_spec.rb +41 -0
  21. data/spec/models/rspeed/env/port_spec.rb +17 -0
  22. data/spec/models/rspeed/env/result_key_spec.rb +19 -0
  23. data/spec/models/rspeed/env/rspeed_spec.rb +43 -0
  24. data/spec/models/rspeed/env/tmp_spec.rb +19 -0
  25. data/spec/models/rspeed/observer/after_spec.rb +0 -2
  26. data/spec/models/rspeed/observer/after_suite_spec.rb +46 -0
  27. data/spec/models/rspeed/observer/before_spec.rb +0 -2
  28. data/spec/models/rspeed/observer/before_suite_spec.rb +24 -2
  29. data/spec/models/rspeed/redis/clean_pipes_flag_spec.rb +14 -0
  30. data/spec/models/rspeed/redis/client_spec.rb +7 -0
  31. data/spec/models/rspeed/redis/destroy_spec.rb +29 -0
  32. data/spec/models/rspeed/redis/get_spec.rb +9 -0
  33. data/spec/models/rspeed/redis/keys_spec.rb +29 -0
  34. data/spec/models/rspeed/redis/result_spec.rb +13 -0
  35. data/spec/models/rspeed/redis/set_spec.rb +9 -0
  36. data/spec/models/rspeed/redis/specs_finished_spec.rb +19 -0
  37. data/spec/models/rspeed/redis/specs_initiated_spec.rb +13 -0
  38. data/spec/models/rspeed/runner/run_spec.rb +30 -0
  39. data/spec/models/rspeed/splitter/actual_examples_spec.rb +6 -2
  40. data/spec/models/rspeed/splitter/append_spec.rb +1 -3
  41. data/spec/models/rspeed/splitter/diff_spec.rb +1 -3
  42. data/spec/models/rspeed/splitter/first_pipe_spec.rb +2 -4
  43. data/spec/models/rspeed/splitter/get_spec.rb +7 -9
  44. data/spec/models/rspeed/splitter/pipe_files_spec.rb +26 -0
  45. data/spec/models/rspeed/splitter/redundant_run_spec.rb +45 -0
  46. data/spec/models/rspeed/splitter/rename_spec.rb +3 -5
  47. data/spec/models/rspeed/splitter/split_spec.rb +70 -34
  48. data/spec/models/rspeed/variable/append_name_spec.rb +19 -0
  49. data/spec/models/rspeed/variable/csv_spec.rb +5 -0
  50. data/spec/models/rspeed/variable/default_partner_spec.rb +5 -0
  51. data/spec/models/rspeed/variable/key_spec.rb +15 -0
  52. data/spec/models/rspeed/variable/pipe_name_spec.rb +15 -0
  53. data/spec/models/rspeed/variable/pipes_pattern_spec.rb +5 -0
  54. data/spec/models/rspeed/variable/result_spec.rb +19 -0
  55. data/spec/models/rspeed/variable/tmp_spec.rb +15 -0
  56. data/spec/{rails_helper.rb → spec_helper.rb} +2 -22
  57. data/spec/support/common.rb +13 -0
  58. data/spec/support/coverage.rb +14 -0
  59. data/spec/support/env_mock.rb +3 -0
  60. data/spec/support/fakeredis.rb +3 -0
  61. metadata +137 -20
  62. data/spec/models/rspeed/splitter/destroy_spec.rb +0 -33
  63. data/spec/models/rspeed/splitter/keys_spec.rb +0 -33
  64. data/spec/models/rspeed/splitter/last_pipe_spec.rb +0 -21
  65. data/spec/models/rspeed/splitter/pipe_spec.rb +0 -21
  66. data/spec/models/rspeed/splitter/pipes_spec.rb +0 -27
  67. data/spec/models/rspeed/splitter/result_spec.rb +0 -19
  68. data/spec/models/rspeed/splitter/save_spec.rb +0 -57
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '.keys' do
4
+ subject(:redis) { described_class }
5
+
6
+ context 'with default config' do
7
+ before do
8
+ described_class.set('rspeed_1', 'value_1')
9
+ described_class.set('rspeed_2', 'value_2')
10
+ described_class.set('rspeed_3', 'value_3')
11
+ end
12
+
13
+ it 'shows keys' do
14
+ expect(redis.keys).to eq %w[rspeed_1 rspeed_2 rspeed_3]
15
+ end
16
+ end
17
+
18
+ context 'with custom key' do
19
+ before do
20
+ described_class.set('custom_key_1', 'value_1')
21
+ described_class.set('custom_key_2', 'value_2')
22
+ described_class.set('custom_key_3', 'value_3')
23
+ end
24
+
25
+ it 'shows keys' do
26
+ expect(redis.keys('custom_key_*')).to eq %w[custom_key_1 custom_key_2 custom_key_3]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '#result?' do
4
+ context 'when has no key rspeed on redis' do
5
+ it { expect(described_class.result?).to be(false) }
6
+ end
7
+
8
+ context 'when has key rspeed on redis' do
9
+ before { described_class.set('rspeed', { files: [[1, '1_spec.rb']], number: 0, total: 1 }.to_json) }
10
+
11
+ it { expect(described_class.result?).to be(true) }
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '.set' do
4
+ it 'sets a key on redis' do
5
+ described_class.set('key', 'value')
6
+
7
+ expect(described_class.client.get('key')).to eq('value')
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '.specs_finished?' do
4
+ before do
5
+ described_class.set('rspeed_pipe_1', '1.0')
6
+
7
+ allow(RSpeed::Env).to receive(:pipes).and_return(2)
8
+ end
9
+
10
+ context 'when the quantity of pipe result is not the same as the quantity of pipes' do
11
+ it { expect(described_class.specs_finished?).to be(false) }
12
+ end
13
+
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') }
16
+
17
+ it { expect(described_class.specs_finished?).to be(true) }
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Redis, '.specs_initiated?' do
4
+ context 'when has no pipe flag key' do
5
+ it { expect(described_class.specs_finished?).to be(false) }
6
+ end
7
+
8
+ context 'when has at least one pipe flag key' do
9
+ before { described_class.set('rspeed_pipe_1', '1.0') }
10
+
11
+ it { expect(described_class.specs_finished?).to be(true) }
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Runner, '#run' do
4
+ let!(:shell) { double('shell') }
5
+ let!(:splitter) { instance_double('RSpeed::Splitter') }
6
+
7
+ before { allow(RSpeed::Splitter).to receive(:new).and_return(splitter) }
8
+
9
+ context 'when is a redundant run' do
10
+ before { allow(splitter).to receive(:redundant_run?).and_return(true) }
11
+
12
+ it 'aborts the run' do
13
+ expect(described_class.run(shell)).to be(nil)
14
+ end
15
+ end
16
+
17
+ context 'when is not a redundant run' do
18
+ before do
19
+ allow(splitter).to receive(:redundant_run?).and_return(false)
20
+ allow(shell).to receive(:call)
21
+ allow(splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
22
+ end
23
+
24
+ it 'run the pipe specs' do
25
+ described_class.run(shell)
26
+
27
+ expect(shell).to have_received(:call).with('bundle exec rspec spec_1.rb spec_2.rb')
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '#actual_examples' do
6
4
  it 'returns all examples' do
7
5
  splitter = described_class.new(specs_path: 'spec/fixtures/**/*_spec.rb')
@@ -19,4 +17,10 @@ RSpec.describe RSpeed::Splitter, '#actual_examples' do
19
17
 
20
18
  expect(splitter.actual_examples).to eq []
21
19
  end
20
+
21
+ it 'does not raise when file is empty' do
22
+ splitter = described_class.new(specs_path: 'spec/fixtures/**/empty.rb')
23
+
24
+ expect(splitter.actual_examples).to eq []
25
+ end
22
26
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '#append' do
6
4
  subject(:splitter) { described_class.new }
7
5
 
@@ -10,7 +8,7 @@ RSpec.describe RSpeed::Splitter, '#append' do
10
8
 
11
9
  expect(splitter.get('rspeed_tmp')).to eq [
12
10
  '{"file":"2_spec.rb","time":2.0}',
13
- '{"file":"1_spec.rb","time":1.0}'
11
+ '{"file":"1_spec.rb","time":1.0}',
14
12
  ]
15
13
  end
16
14
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '#diff' do
6
4
  subject(:splitter) { described_class.new(specs_path: './spec/fixtures/*_spec.rb') }
7
5
 
@@ -15,7 +13,7 @@ RSpec.describe RSpeed::Splitter, '#diff' do
15
13
  redis.lpush 'rspeed', { file: './spec/fixtures/2_spec.rb:666', time: '6' }.to_json
16
14
  redis.lpush 'rspeed', { file: './spec/fixtures/x_spec.rb:1', time: 3 }.to_json
17
15
 
18
- File.open('spec/fixtures/new_spec.rb', 'a') { |file| file.write("it") }
16
+ File.open('spec/fixtures/new_spec.rb', 'a') { |file| file.write('it') }
19
17
  end
20
18
 
21
19
  after { delete_file('spec/fixtures/new_spec.rb') }
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '.first_pipe?' do
6
4
  subject(:splitter) { described_class.new }
7
5
 
8
6
  context 'when pipe env is 1' do
9
- before { allow(splitter).to receive(:pipe).and_return 1 }
7
+ before { allow(RSpeed::Env).to receive(:pipe).and_return 1 }
10
8
 
11
9
  it { expect(splitter.first_pipe?).to eq true }
12
10
  end
13
11
 
14
12
  context 'when pipe env is not 1' do
15
- before { allow(splitter).to receive(:pipe).and_return 2 }
13
+ before { allow(RSpeed::Env).to receive(:pipe).and_return 2 }
16
14
 
17
15
  it { expect(splitter.first_pipe?).to eq false }
18
16
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '#get' do
6
4
  subject(:splitter) { described_class.new }
7
5
 
@@ -18,14 +16,14 @@ RSpec.describe RSpeed::Splitter, '#get' do
18
16
  {
19
17
  'files' => [[1, '1_spec.rb'], [2, '2_spec.rb']],
20
18
  'number' => 0,
21
- 'total' => 3
19
+ 'total' => 3,
22
20
  },
23
21
 
24
22
  {
25
23
  'files' => [[3, '3_spec.rb']],
26
24
  'number' => 1,
27
- 'total' => 3
28
- }
25
+ 'total' => 3,
26
+ },
29
27
  ]
30
28
  end
31
29
  end
@@ -40,8 +38,8 @@ RSpec.describe RSpeed::Splitter, '#get' do
40
38
  {
41
39
  'files' => [[1, '1_spec.rb'], [2, '2_spec.rb']],
42
40
  'number' => 0,
43
- 'total' => 3
44
- }
41
+ 'total' => 3,
42
+ },
45
43
  ]
46
44
  end
47
45
  end
@@ -55,7 +53,7 @@ RSpec.describe RSpeed::Splitter, '#get' do
55
53
  it 'executes the right fetch method' do
56
54
  expect(splitter.get('rspeed')).to eq [
57
55
  '{"file":"2_spec.rb","time":2}',
58
- '{"file":"1_spec.rb","time":1}'
56
+ '{"file":"1_spec.rb","time":1}',
59
57
  ]
60
58
  end
61
59
  end
@@ -69,7 +67,7 @@ RSpec.describe RSpeed::Splitter, '#get' do
69
67
  it 'executes the right fetch method' do
70
68
  expect(splitter.get('rspeed_tmp')).to eq [
71
69
  '{"file":"2_spec.rb","time":2}',
72
- '{"file":"1_spec.rb","time":1}'
70
+ '{"file":"1_spec.rb","time":1}',
73
71
  ]
74
72
  end
75
73
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
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
+ context 'when has no result' do
10
+ before { allow(RSpeed::Redis).to receive(:result?).and_return(false) }
11
+
12
+ it { expect(splitter.pipe_files).to be(nil) }
13
+ end
14
+
15
+ context 'when has result' do
16
+ before do
17
+ allow(RSpeed::Redis).to receive(:result?).and_return(true)
18
+
19
+ allow(splitter).to receive(:split).and_return(rspeed_1: { files: [{ file: 'spec_1.rb' }, { file: 'spec_2.rb' }] })
20
+ end
21
+
22
+ it 'returns the splitted pipe files' do
23
+ expect(splitter.pipe_files).to eq 'spec_1.rb spec_2.rb'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Splitter, '.redundant_run?' do
4
+ subject(:splitter) { described_class.new }
5
+
6
+ context 'when is not pipe 1' do
7
+ before { allow(RSpeed::Env).to receive(:pipe).and_return(2) }
8
+
9
+ context 'when result key exists' do
10
+ let!(:redis) { redis_object }
11
+
12
+ before do
13
+ redis.set('rspeed', '{}')
14
+
15
+ allow(RSpeed::Env).to receive(:pipe).and_return(2)
16
+ end
17
+
18
+ it { expect(splitter.redundant_run?).to be(false) }
19
+ end
20
+
21
+ context 'when result key does not exist' do
22
+ it { expect(splitter.redundant_run?).to be(true) }
23
+ end
24
+ end
25
+
26
+ context 'when is the first pipe' do
27
+ before { allow(RSpeed::Env).to receive(:pipe).and_return(1) }
28
+
29
+ context 'when result key exists' do
30
+ let!(:redis) { redis_object }
31
+
32
+ before do
33
+ redis.set('rspeed', '{}')
34
+
35
+ allow(RSpeed::Env).to receive(:pipe).and_return(2)
36
+ end
37
+
38
+ it { expect(splitter.redundant_run?).to be(false) }
39
+ end
40
+
41
+ context 'when result key does not exist' do
42
+ it { expect(splitter.redundant_run?).to be(false) }
43
+ end
44
+ end
45
+ end
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '#rename' do
6
4
  subject(:splitter) { described_class.new }
7
5
 
8
6
  let!(:redis) { redis_object }
9
7
 
10
- before { redis.lpush 'rspeed_tmp', { file: '1_spec.rb', time: 1.0 }.to_json }
8
+ before { redis.lpush('rspeed_tmp', { file: '1_spec.rb', time: 1.0 }.to_json) }
11
9
 
12
10
  it 'renames the key' do
13
11
  splitter.rename
14
12
 
15
- expect(redis.lrange('rspeed_tmp', 0, -1)).to eq []
16
- expect(redis.lrange('rspeed', 0, -1)).to eq ['{"file":"1_spec.rb","time":1.0}']
13
+ expect(redis.lrange('rspeed_tmp', 0, -1)).to eq([])
14
+ expect(redis.lrange('rspeed', 0, -1)).to eq(['{"file":"1_spec.rb","time":1.0}'])
17
15
  end
18
16
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_helper'
4
-
5
3
  RSpec.describe RSpeed::Splitter, '.split' do
6
4
  subject(:splitter) { described_class.new }
7
5
 
@@ -17,37 +15,75 @@ RSpec.describe RSpeed::Splitter, '.split' do
17
15
  ]
18
16
  end
19
17
 
20
- before { allow(splitter).to receive(:pipes).and_return 3 }
21
-
22
- it 'splits the times between the pipes' do
23
- expect(splitter.split(unsorted_data)).to eq(
24
- rspeed_1: {
25
- files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
26
- number: 1,
27
- total: 2.0
28
- },
29
-
30
- rspeed_2: {
31
- files: [
32
- { file: './spec/1_5_spec.rb', time: 1.5 },
33
- { file: './spec/0_4_spec.rb', time: 0.4 },
34
- { file: './spec/0_2_spec.rb', time: 0.2 }
35
- ],
36
-
37
- number: 2,
38
- total: 1.5 + 0.4 + 0.2 # 1.5 -> 1.9 -> 2.1
39
- },
40
-
41
- rspeed_3: {
42
- files: [
43
- { file: './spec/1_1_spec.rb', time: 1.1 },
44
- { file: './spec/0_7_spec.rb', time: 0.7 },
45
- { file: './spec/0_3_spec.rb', time: 0.3 }
46
- ],
47
-
48
- number: 3,
49
- total: 1.1 + 0.7 + 0.3 # 1.1 -> 1.8 -> 2.1
50
- }
51
- )
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(
59
+ rspeed_1: {
60
+ files: [{ file: './spec/2_0_spec.rb', time: 2.0 }],
61
+ number: 1,
62
+ total: 2.0,
63
+ },
64
+
65
+ rspeed_2: {
66
+ files: [
67
+ { file: './spec/1_5_spec.rb', time: 1.5 },
68
+ { file: './spec/0_4_spec.rb', time: 0.4 },
69
+ { file: './spec/0_2_spec.rb', time: 0.2 },
70
+ ],
71
+
72
+ number: 2,
73
+ total: 1.5 + 0.4 + 0.2, # 1.5 -> 1.9 -> 2.1
74
+ },
75
+
76
+ rspeed_3: {
77
+ files: [
78
+ { file: './spec/1_1_spec.rb', time: 1.1 },
79
+ { file: './spec/0_7_spec.rb', time: 0.7 },
80
+ { file: './spec/0_3_spec.rb', time: 0.3 },
81
+ ],
82
+
83
+ number: 3,
84
+ total: 1.1 + 0.7 + 0.3, # 1.1 -> 1.8 -> 2.1
85
+ }
86
+ )
87
+ end
52
88
  end
53
89
  end