rspeed 0.1.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/README.md +11 -7
  4. data/lib/generators/rspeed/install_generator.rb +1 -1
  5. data/lib/rspeed.rb +9 -5
  6. data/lib/rspeed/env.rb +43 -0
  7. data/lib/rspeed/extension.rb +6 -37
  8. data/lib/rspeed/logger.rb +11 -0
  9. data/lib/rspeed/observer.rb +43 -0
  10. data/lib/rspeed/redis.rb +55 -0
  11. data/lib/rspeed/runner.rb +4 -17
  12. data/lib/rspeed/splitter.rb +65 -73
  13. data/lib/rspeed/variable.rb +31 -0
  14. data/lib/rspeed/version.rb +1 -1
  15. data/spec/common_helper.rb +10 -0
  16. data/spec/fixtures/1_spec.rb +9 -0
  17. data/spec/fixtures/2_spec.rb +5 -0
  18. data/spec/fixtures/empty.rb +4 -0
  19. data/spec/fixtures/new_spec.rb.csv +1 -0
  20. data/spec/models/rspeed/env/db_spec.rb +17 -0
  21. data/spec/models/rspeed/env/host_spec.rb +17 -0
  22. data/spec/models/rspeed/env/name_spec.rb +17 -0
  23. data/spec/models/rspeed/env/pipe_spec.rb +19 -0
  24. data/spec/models/rspeed/env/pipes_spec.rb +19 -0
  25. data/spec/models/rspeed/env/port_spec.rb +17 -0
  26. data/spec/models/rspeed/env/result_key_spec.rb +19 -0
  27. data/spec/models/rspeed/env/rspeed_spec.rb +43 -0
  28. data/spec/models/rspeed/env/tmp_spec.rb +19 -0
  29. data/spec/models/rspeed/observer/after_spec.rb +16 -0
  30. data/spec/models/rspeed/observer/after_suite_spec.rb +70 -0
  31. data/spec/models/rspeed/observer/before_spec.rb +15 -0
  32. data/spec/models/rspeed/observer/before_suite_spec.rb +37 -0
  33. data/spec/models/rspeed/redis/clean_spec.rb +12 -0
  34. data/spec/models/rspeed/redis/client_spec.rb +7 -0
  35. data/spec/models/rspeed/redis/destroy_spec.rb +29 -0
  36. data/spec/models/rspeed/redis/get_spec.rb +9 -0
  37. data/spec/models/rspeed/redis/keys_spec.rb +29 -0
  38. data/spec/models/rspeed/redis/result_spec.rb +13 -0
  39. data/spec/models/rspeed/redis/set_spec.rb +9 -0
  40. data/spec/models/rspeed/redis/specs_finished_spec.rb +19 -0
  41. data/spec/models/rspeed/redis/specs_initiated_spec.rb +13 -0
  42. data/spec/models/rspeed/runner/run_spec.rb +47 -0
  43. data/spec/models/rspeed/splitter/actual_examples_spec.rb +26 -0
  44. data/spec/models/rspeed/splitter/append_question_spec.rb +37 -0
  45. data/spec/models/rspeed/splitter/append_spec.rb +6 -3
  46. data/spec/models/rspeed/splitter/diff_spec.rb +15 -14
  47. data/spec/models/rspeed/splitter/first_pipe_spec.rb +2 -4
  48. data/spec/models/rspeed/splitter/get_spec.rb +7 -9
  49. data/spec/models/rspeed/splitter/need_warm_question_spec.rb +37 -0
  50. data/spec/models/rspeed/splitter/pipe_files_spec.rb +26 -0
  51. data/spec/models/rspeed/splitter/rename_spec.rb +3 -5
  52. data/spec/models/rspeed/splitter/split_spec.rb +72 -36
  53. data/spec/models/rspeed/variable/append_name_spec.rb +19 -0
  54. data/spec/models/rspeed/variable/csv_spec.rb +5 -0
  55. data/spec/models/rspeed/variable/default_partner_spec.rb +5 -0
  56. data/spec/models/rspeed/variable/key_spec.rb +15 -0
  57. data/spec/models/rspeed/variable/pipe_name_spec.rb +15 -0
  58. data/spec/models/rspeed/variable/pipes_pattern_spec.rb +5 -0
  59. data/spec/models/rspeed/variable/result_spec.rb +19 -0
  60. data/spec/models/rspeed/variable/tmp_spec.rb +15 -0
  61. data/spec/spec_helper.rb +27 -0
  62. data/spec/support/common.rb +13 -0
  63. data/spec/support/coverage.rb +14 -0
  64. data/spec/support/env_mock.rb +3 -0
  65. data/spec/support/fakeredis.rb +3 -0
  66. metadata +155 -20
  67. data/spec/models/rspeed/splitter/destroy_spec.rb +0 -33
  68. data/spec/models/rspeed/splitter/keys_spec.rb +0 -33
  69. data/spec/models/rspeed/splitter/last_pipe_spec.rb +0 -21
  70. data/spec/models/rspeed/splitter/pipe_spec.rb +0 -21
  71. data/spec/models/rspeed/splitter/pipes_spec.rb +0 -27
  72. data/spec/models/rspeed/splitter/result_spec.rb +0 -19
  73. data/spec/models/rspeed/splitter/save_spec.rb +0 -55
  74. data/spec/rails_helper.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa530fc36a8a38f31b2f241cb0c322bd268f0928cb5929f89d4b939e54b740a3
4
- data.tar.gz: 4228e7997bd6d4b51da7aa66ef10ddc25474a184cd3c42d42afd6077db777f8d
3
+ metadata.gz: de6e5d6c3ca630b15b835939ec2b01adbeec526480efde16052c294f297457af
4
+ data.tar.gz: 4c4d1efdf65c9f4c01106f1fe109d8ffb2160e40b6f90813b4bdc813061613dc
5
5
  SHA512:
6
- metadata.gz: ce7fa5fe6f56cdf9b3f9a02cc040a8180d21e3c5ad1c08bcc792df3ee336c300c6fd5d8438cef908815a896dc961a5743910a63686653c6fdc91707ec24b4a6b
7
- data.tar.gz: ae309883ef9f2f63792644583c1b9277e8c290e84172b59e7eecb0a961015d48b9411a798a6514d6dd3855a3553ce4d31e420634514f37025f4023a4c181e133
6
+ metadata.gz: 5ab45f421853bee217c88cfad0efd5d2bd16b9968b17b7676593b4ae0a2e708ac6b646f40845b8f186adfc000c505cef4e95f77c7c8273e6964203b0de22420a
7
+ data.tar.gz: 7e32c34c76fcdaff18e2aa2726c232d42c32fb4e3fc55b452f0d9b62f2dff0e5f458acd4c3dbacae75b5ca0c330e4b2792618179675c11adcf8aa566d13106c9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,37 @@
1
+ ## master
2
+
3
+ - None;
4
+
5
+ ## v0.5.1
6
+
7
+ #### Fix
8
+
9
+ - Only pipe number 1 will warm up avoiding duplicated spec entries;
10
+
11
+ ## v0.5.0
12
+
13
+ #### Fix
14
+
15
+ - Add env `RSPEED_NAME` to specify the application name and avoid result conflicts between multiple runs;
16
+ - No more depends on pipe sequence to generate ou aggregate the resul;
17
+ - rake `rspeed:install`;
18
+
19
+ #### Update
20
+
21
+ - The result of the pipes are no more saved on Redis. It's now calculated based on result key `rspeed`;
22
+
23
+ ## v0.4.0
24
+
25
+ - Now we make diff to discover removed and added examples;
26
+
27
+ ## v0.3.0
28
+
29
+ - Removed and added files now is considered on run;
30
+
31
+ ## v0.2.0
32
+
33
+ - Splits specs by examples over files;
34
+
1
35
  ## v0.1.0
2
36
 
3
37
  - First release;
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # RSpeed
2
2
 
3
- [![Build Status](https://github.com/wbotelhos/rspeed/workflows/CI/badge.svg)](https://github.com/wbotelhos/rspeed/actions)
3
+ [![CI](https://github.com/wbotelhos/rspeed/workflows/CI/badge.svg)](https://github.com/wbotelhos/rspeed/actions)
4
4
  [![Gem Version](https://badge.fury.io/rb/rspeed.svg)](https://badge.fury.io/rb/rspeed)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/cc5efe8b06bc1d5e9e8a/maintainability)](https://codeclimate.com/github/wbotelhos/rspeed/maintainability)
6
- [![Patreon](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://www.patreon.com/wbotelhos)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f312587b4f126bb13e85/maintainability)](https://codeclimate.com/github/wbotelhos/rspeed/maintainability)
6
+ [![Coverage](https://codecov.io/gh/wbotelhos/rspeed/branch/main/graph/badge.svg)](https://codecov.io/gh/wbotelhos/rspeed)
7
+ [![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://www.patreon.com/wbotelhos)
7
8
 
8
9
  RSpeed splits your specs to you run parallels tests.
9
10
 
@@ -25,19 +26,22 @@ rake rspeed:install
25
26
 
26
27
  ## Usage
27
28
 
28
- - `RSPEED`: Enables RSpeed
29
- - `RSPEED_PIPES`: Quantity of pipes
29
+ - `RSPEED_NAME`: You app name to avoid data override
30
30
  - `RSPEED_PIPE`: Current pipe
31
+ - `RSPEED_PIPES`: Quantity of pipes
32
+ - `RSPEED_RESULT_KEY`: The key that keeps the final result of all pipes
33
+ - `RSPEED_TMP_KEY`: The temporary key that keeps the partial result of the pipes
34
+ - `RSPEED`: Enables RSpeed
31
35
 
32
36
  ```sh
33
- RSPEED=true RSPEED_PIPES=3 RSPEED_PIPE=1 bundle exec rake rspeed:run
37
+ RSPEED=true RSPEED_NAME=authorizy RSPEED_PIPE=1 RSPEED_PIPES=3 bundle exec rake rspeed:run
34
38
  ```
35
39
 
36
40
  ## How it Works
37
41
 
38
42
  ### First run
39
43
 
40
- 1. Since we has no statistics on the first time, we run all specs and collect it;
44
+ 1. Since we have no statistics on the first time, we run all specs and collect it;
41
45
 
42
46
  ```json
43
47
  { "file": "./spec/models/1_spec.rb", "time": 0.01 }
@@ -6,7 +6,7 @@ module RSpeed
6
6
 
7
7
  desc 'Creates RSpeed task'
8
8
 
9
- def copy_initializer
9
+ def create_initializer
10
10
  copy_file 'lib/tasks/rspeed.rake', 'lib/tasks/rspeed.rake'
11
11
  end
12
12
  end
data/lib/rspeed.rb CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  module RSpeed
4
4
  require 'csv'
5
- require 'redis'
6
- end
7
5
 
8
- require 'rspeed/extension'
9
- require 'rspeed/runner'
10
- require 'rspeed/splitter'
6
+ require 'rspeed/env'
7
+ require 'rspeed/extension'
8
+ require 'rspeed/logger'
9
+ require 'rspeed/observer'
10
+ require 'rspeed/redis'
11
+ require 'rspeed/runner'
12
+ require 'rspeed/splitter'
13
+ require 'rspeed/variable'
14
+ end
data/lib/rspeed/env.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Env
5
+ module_function
6
+
7
+ def db
8
+ ENV['RSPEED_DB']&.to_i
9
+ end
10
+
11
+ def host
12
+ ENV['RSPEED_HOST']
13
+ end
14
+
15
+ def name
16
+ ENV['RSPEED_NAME']
17
+ end
18
+
19
+ def pipe
20
+ ENV.fetch('RSPEED_PIPE', 1).to_i
21
+ end
22
+
23
+ def pipes
24
+ ENV.fetch('RSPEED_PIPES', 1).to_i
25
+ end
26
+
27
+ def port
28
+ ENV['RSPEED_PORT']&.to_i
29
+ end
30
+
31
+ def result_key
32
+ ENV.fetch('RESPEED_RESULT_KEY', RSpeed::Variable.result)
33
+ end
34
+
35
+ def rspeed
36
+ ENV['RSPEED'] == 'true'
37
+ end
38
+
39
+ def tmp_key
40
+ ENV.fetch('RESPEED_TMP_KEY', RSpeed::Variable.tmp)
41
+ end
42
+ end
43
+ end
@@ -1,43 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if ENV['RSPEED'] == 'true'
4
- require 'rspec/rails'
3
+ if RSpeed::Env.rspeed
4
+ require 'rspec'
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) }
10
+ config.after(:suite) { RSpeed::Observer.after_suite }
42
11
  end
43
12
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Logger
5
+ module_function
6
+
7
+ def log(message)
8
+ puts(message)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
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::Variable::CSV, 'a') do |file|
13
+ file.write("#{spent_time},#{file_path}:#{line_number}\n")
14
+ end
15
+ end
16
+
17
+ def after_suite(splitter = ::RSpeed::Splitter.new)
18
+ RSpeed::Redis.set(RSpeed::Variable.pipe_name, true)
19
+
20
+ splitter.append if splitter.append?
21
+
22
+ return unless RSpeed::Redis.specs_finished?
23
+
24
+ splitter.rename
25
+
26
+ RSpeed::Redis.clean
27
+ end
28
+
29
+ def before(example)
30
+ example.update_inherited_metadata(start_at: example.clock.now)
31
+ end
32
+
33
+ def before_suite
34
+ truncate_csv_file
35
+
36
+ RSpeed::Redis.destroy(RSpeed::Variable.tmp) unless RSpeed::Redis.specs_initiated?
37
+ end
38
+
39
+ def truncate_csv_file
40
+ File.open(RSpeed::Variable::CSV, 'w') { |file| file.truncate(0) }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Redis
5
+ require 'redis'
6
+
7
+ module_function
8
+
9
+ def clean
10
+ destroy(RSpeed::Variable::PIPES_PATTERN)
11
+ end
12
+
13
+ def client
14
+ @client ||= ::Redis.new(db: RSpeed::Env.db, host: RSpeed::Env.host, port: RSpeed::Env.port)
15
+ end
16
+
17
+ def destroy(pattern = RSpeed::Variable::DEFAULT_PATTERN)
18
+ keys(pattern).each { |key| client.del(key) }
19
+ end
20
+
21
+ def get(key)
22
+ client.get(key)
23
+ end
24
+
25
+ def keys(pattern = RSpeed::Variable::DEFAULT_PATTERN)
26
+ cursor = 0
27
+ result = []
28
+
29
+ loop do
30
+ cursor, results = client.scan(cursor, match: pattern)
31
+ result += results
32
+
33
+ break if cursor.to_i.zero?
34
+ end
35
+
36
+ result
37
+ end
38
+
39
+ def result?
40
+ keys(RSpeed::Env.result_key).any?
41
+ end
42
+
43
+ def set(key, value)
44
+ client.set(key, value)
45
+ end
46
+
47
+ def specs_finished?
48
+ RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).size == RSpeed::Env.pipes
49
+ end
50
+
51
+ def specs_initiated?
52
+ RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).any?
53
+ end
54
+ end
55
+ end
data/lib/rspeed/runner.rb CHANGED
@@ -4,25 +4,12 @@ module RSpeed
4
4
  module Runner
5
5
  module_function
6
6
 
7
- def run(shell)
8
- splitter = ::RSpeed::Splitter.new
7
+ def run(shell, splitter: ::RSpeed::Splitter.new)
8
+ return shell.call(['bundle exec rspec', splitter.pipe_files].compact.join(' ')) if splitter.need_warm?
9
9
 
10
- if splitter.first_pipe?
11
- # splitter.destroy "rspeed_*"
12
- splitter.destroy 'rspeed_tmp'
13
- end
10
+ RSpeed::Logger.log("Pipe #{RSpeed::Env.pipe} skipped. Only Pipe 1 can warm.")
14
11
 
15
- if splitter.result?
16
- splitter.save if splitter.first_pipe?
17
-
18
- files = splitter.get("rspeed_#{splitter.pipe}")[0]['files'].map { |item| item['file'] }.join(' ')
19
- end
20
-
21
- shell.call ['bundle exec rspec', files].compact.join(' ')
22
-
23
- splitter.append
24
-
25
- splitter.rename if splitter.last_pipe?
12
+ RSpeed::Observer.after_suite
26
13
  end
27
14
  end
28
15
  end
@@ -2,87 +2,87 @@
2
2
 
3
3
  module RSpeed
4
4
  class Splitter
5
- DEFAULT_PATTERN = 'rspeed_*'
5
+ require 'json'
6
6
 
7
- def append(files = file_data)
8
- files.each do |time, file|
9
- redis.lpush 'rspeed_tmp', { file: file, time: time.to_f }.to_json
10
- end
7
+ def initialize(specs_path: './spec/**/*_spec.rb')
8
+ @specs_path = specs_path
11
9
  end
12
10
 
13
- def destroy(pattern = DEFAULT_PATTERN)
14
- keys(pattern).each { |key| redis.del key }
15
- end
11
+ def actual_examples
12
+ @actual_examples ||= begin
13
+ [].tap do |examples|
14
+ Dir[@specs_path].sort.each do |file|
15
+ data = File.open(file).read
16
+ lines = data.split("\n")
16
17
 
17
- def diff
18
- (actual_files + added_files).sort_by { |item| item[:time].to_f }.map do |item|
19
- [item[:time], item[:file]]
18
+ lines&.each&.with_index do |item, index|
19
+ examples << "#{file}:#{index + 1}" if /^it/.match?(item.gsub(/\s+/, ''))
20
+ end
21
+ end
22
+
23
+ stream(:actual_examples, examples)
24
+ end
20
25
  end
21
26
  end
22
27
 
23
- def first_pipe?
24
- pipe == 1
28
+ def append?
29
+ RSpeed::Redis.result? || first_pipe?
25
30
  end
26
31
 
27
- def get(pattern)
28
- @get ||= begin
29
- return redis.lrange(pattern, 0, -1) if %w[rspeed rspeed_tmp].include?(pattern)
30
-
31
- keys(pattern).map { |key| JSON.parse redis.get(key) }
32
+ def append(files = CSV.read(RSpeed::Variable::CSV))
33
+ files.each do |time, file|
34
+ redis.lpush(RSpeed::Env.tmp_key, { file: file, time: time.to_f }.to_json)
32
35
  end
33
36
  end
34
37
 
35
- def keys(pattern = DEFAULT_PATTERN)
36
- cursor = 0
37
- result = []
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 } }
38
41
 
39
- loop do
40
- cursor, results = redis.scan(cursor, match: pattern)
41
- result += results
42
+ removed_examples # called just for stream for now
42
43
 
43
- break if cursor.to_i.zero?
44
- end
45
-
46
- result
44
+ actual_data + added_data
47
45
  end
48
46
 
49
- def last_pipe?
50
- pipe == pipes
47
+ def first_pipe?
48
+ RSpeed::Env.pipe == 1
51
49
  end
52
50
 
53
- def pipe
54
- ENV.fetch('RSPEED_PIPE') { 1 }.to_i
55
- end
51
+ def get(pattern)
52
+ @get ||= begin
53
+ return redis.lrange(pattern, 0, -1) if [RSpeed::Variable.result, RSpeed::Variable.tmp].include?(pattern)
56
54
 
57
- def pipes
58
- result? ? ENV.fetch('RSPEED_PIPES') { 1 }.to_i : 1
55
+ RSpeed::Redis.keys(pattern).map { |key| ::JSON.parse(redis.get(key)) }
56
+ end
59
57
  end
60
58
 
61
- def rename
62
- redis.rename 'rspeed_tmp', 'rspeed'
59
+ def need_warm?
60
+ first_pipe? && !RSpeed::Redis.result?
63
61
  end
64
62
 
65
- def result?
66
- !keys('rspeed').empty?
63
+ def pipe_files
64
+ return unless RSpeed::Redis.result?
65
+
66
+ split[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].map { |item| item[:file] }.join(' ')
67
67
  end
68
68
 
69
- def save(data = rspeed_data)
70
- split(data).each do |key, value|
71
- redis.set key, value.to_json
72
- end
69
+ def rename
70
+ redis.rename(RSpeed::Env.tmp_key, RSpeed::Env.result_key)
73
71
  end
74
72
 
75
- def split(data)
73
+ def split(data = diff)
76
74
  json = {}
77
75
 
78
- pipes.times do |index|
79
- json["rspeed_#{index + 1}".to_sym] ||= []
80
- json["rspeed_#{index + 1}".to_sym] = { total: 0, files: [], number: index + 1 }
76
+ RSpeed::Env.pipes.times do |index|
77
+ json[RSpeed::Variable.key(index + 1)] ||= []
78
+ json[RSpeed::Variable.key(index + 1)] = { total: 0, files: [], number: index + 1 }
81
79
  end
82
80
 
83
- data.each do |record|
81
+ sorted_data = data.sort_by { |item| item[:time] }.reverse
82
+
83
+ sorted_data.each do |record|
84
84
  selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
85
- selected_pipe = json["rspeed_#{selected_pipe_data[1][:number]}".to_sym]
85
+ selected_pipe = json[RSpeed::Variable.key(selected_pipe_data[1][:number])]
86
86
  time = record[:time].to_f
87
87
 
88
88
  selected_pipe[:total] += time
@@ -94,44 +94,36 @@ module RSpeed
94
94
 
95
95
  private
96
96
 
97
- def actual_files
98
- rspeed_data.select { |item| actual_specs.include?(item[:file]) }
99
- end
100
-
101
- def actual_specs
102
- Dir['./spec/**/*_spec.rb']
103
- end
104
-
105
- def added_files
106
- added_specs.map { |item| { file: item, time: 0 } }
107
- end
108
-
109
- def added_specs
110
- actual_specs - saved_specs
111
- end
112
-
113
- def file_data
114
- CSV.read('rspeed.csv')
97
+ def added_examples
98
+ @added_examples ||= begin
99
+ (actual_examples - rspeed_examples).tap { |examples| stream(:added_examples, examples) }
100
+ end
115
101
  end
116
102
 
117
103
  def redis
118
- @redis ||= ::Redis.new(db: ENV['RSPEED_DB'], host: ENV['RSPEED_HOST'], port: ENV.fetch('RSPEED_PORT') { 6379 })
104
+ @redis ||= ::RSpeed::Redis.client
119
105
  end
120
106
 
121
- def removed_specs
122
- saved_specs - actual_specs
107
+ def removed_examples
108
+ @removed_examples ||= begin
109
+ (rspeed_examples - actual_examples).tap { |examples| stream(:removed_examples, examples) }
110
+ end
123
111
  end
124
112
 
125
113
  def removed_time
126
- removed_specs.map { |item| item[0].to_f }.sum
114
+ removed_examples.sum { |item| item[0].to_f }
127
115
  end
128
116
 
129
117
  def rspeed_data
130
- get('rspeed').map { |item| JSON.parse item, symbolize_names: true }
118
+ @rspeed_data ||= get(RSpeed::Env.result_key).map { |item| JSON.parse(item, symbolize_names: true) }
131
119
  end
132
120
 
133
- def saved_specs
121
+ def rspeed_examples
134
122
  rspeed_data.map { |item| item[:file] }
135
123
  end
124
+
125
+ def stream(type, data)
126
+ RSpeed::Logger.log("PIPE: #{RSpeed::Env.pipe} with #{type}: #{data}")
127
+ end
136
128
  end
137
129
  end