rspeed 0.2.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/README.md +10 -7
  4. data/lib/generators/rspeed/install_generator.rb +1 -1
  5. data/lib/rspeed.rb +8 -7
  6. data/lib/rspeed/env.rb +39 -0
  7. data/lib/rspeed/extension.rb +3 -2
  8. data/lib/rspeed/logger.rb +11 -0
  9. data/lib/rspeed/observer.rb +21 -6
  10. data/lib/rspeed/redis.rb +64 -0
  11. data/lib/rspeed/runner.rb +5 -16
  12. data/lib/rspeed/splitter.rb +66 -71
  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/observer/after_spec.rb +5 -5
  29. data/spec/models/rspeed/observer/after_suite_spec.rb +57 -0
  30. data/spec/models/rspeed/observer/before_spec.rb +0 -2
  31. data/spec/models/rspeed/observer/before_suite_spec.rb +17 -6
  32. data/spec/models/rspeed/redis/clean_spec.rb +20 -0
  33. data/spec/models/rspeed/redis/client_spec.rb +7 -0
  34. data/spec/models/rspeed/redis/destroy_spec.rb +29 -0
  35. data/spec/models/rspeed/redis/get_spec.rb +9 -0
  36. data/spec/models/rspeed/redis/keys_spec.rb +29 -0
  37. data/spec/models/rspeed/redis/result_spec.rb +13 -0
  38. data/spec/models/rspeed/redis/set_spec.rb +9 -0
  39. data/spec/models/rspeed/redis/specs_finished_spec.rb +19 -0
  40. data/spec/models/rspeed/redis/specs_initiated_spec.rb +13 -0
  41. data/spec/models/rspeed/runner/run_spec.rb +77 -0
  42. data/spec/models/rspeed/splitter/actual_examples_spec.rb +26 -0
  43. data/spec/models/rspeed/splitter/append_question_spec.rb +37 -0
  44. data/spec/models/rspeed/splitter/append_spec.rb +9 -27
  45. data/spec/models/rspeed/splitter/diff_spec.rb +15 -14
  46. data/spec/models/rspeed/splitter/first_pipe_spec.rb +2 -4
  47. data/spec/models/rspeed/splitter/get_spec.rb +6 -22
  48. data/spec/models/rspeed/splitter/need_warm_question_spec.rb +37 -0
  49. data/spec/models/rspeed/splitter/pipe_files_spec.rb +26 -0
  50. data/spec/models/rspeed/splitter/rename_spec.rb +13 -6
  51. data/spec/models/rspeed/splitter/split_spec.rb +70 -34
  52. data/spec/models/rspeed/variable/append_name_spec.rb +19 -0
  53. data/spec/models/rspeed/variable/default_partner_spec.rb +5 -0
  54. data/spec/models/rspeed/variable/key_spec.rb +15 -0
  55. data/spec/models/rspeed/variable/pipe_name_spec.rb +15 -0
  56. data/spec/models/rspeed/variable/pipe_profile_spec.rb +15 -0
  57. data/spec/models/rspeed/variable/pipes_pattern_spec.rb +5 -0
  58. data/spec/models/rspeed/variable/profile_pattern_spec.rb +5 -0
  59. data/spec/models/rspeed/variable/result_spec.rb +19 -0
  60. data/spec/spec_helper.rb +27 -0
  61. data/spec/support/common.rb +13 -0
  62. data/spec/support/coverage.rb +14 -0
  63. data/spec/support/env_mock.rb +3 -0
  64. data/spec/support/fakeredis.rb +3 -0
  65. metadata +146 -20
  66. data/spec/models/rspeed/splitter/destroy_spec.rb +0 -33
  67. data/spec/models/rspeed/splitter/keys_spec.rb +0 -33
  68. data/spec/models/rspeed/splitter/last_pipe_spec.rb +0 -21
  69. data/spec/models/rspeed/splitter/pipe_spec.rb +0 -21
  70. data/spec/models/rspeed/splitter/pipes_spec.rb +0 -27
  71. data/spec/models/rspeed/splitter/result_spec.rb +0 -19
  72. data/spec/models/rspeed/splitter/save_spec.rb +0 -55
  73. data/spec/rails_helper.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27a64c0a7ba3f1c113bbdf8f060be44dad913a684d234663b342a537937ac7f2
4
- data.tar.gz: 47d3a190302b361c6bb76279094a7c04982492e59d099d6acdbe92fcbd26d648
3
+ metadata.gz: 4a58e610b2982e8a8f81783f5704f0a136c971aa6df1a446cf32ce7a53485120
4
+ data.tar.gz: 41c88139eff91637c52cda59b1239ca1833aa0db886677d0a33c51564d500a19
5
5
  SHA512:
6
- metadata.gz: ac35df999459a32e06989e84d0e703f52a61b896e3a68ef7993c6eaf70952dd05826dffdf36f01fe5843b3916e57b24112708cbcadd19b83eb018c990f2bda4c
7
- data.tar.gz: '09feaa28dc6a306f8ba039bcfbf02b500450b6f117160a726f326daae76c9584524825ffd693a4f3a84a61cb181fef7c00216557ce04ccaea736f42d3e9370d8'
6
+ metadata.gz: 67b9c9d9334b315b9392bf7a52965bc1884ab67c96345abf3f037b185010b4de24f9b895cc306567f9cf07737786d7f58edc4ab14f0e45a26acef8acd525ed2f
7
+ data.tar.gz: e2771f90d265bbfc5ea3273c82aa467dee40b3f5cbfc40ac0c7501da4577664c28bd11b491a1568907775584490a36e3c4d5c1935cc375aca27ff8713e9b0b00
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## master
2
+
3
+ - CSV dependency dropped;
4
+ - Drops tmp key in favor of profile keys fetch;
5
+
6
+ ## v0.5.1
7
+
8
+ #### Fix
9
+
10
+ - Only pipe number 1 will warm up avoiding duplicated spec entries;
11
+
12
+ ## v0.5.0
13
+
14
+ #### Fix
15
+
16
+ - Add env `RSPEED_NAME` to specify the application name and avoid result conflicts between multiple runs;
17
+ - No more depends on pipe sequence to generate ou aggregate the resul;
18
+ - rake `rspeed:install`;
19
+
20
+ #### Update
21
+
22
+ - The result of the pipes are no more saved on Redis. It's now calculated based on result key `rspeed`;
23
+
24
+ ## v0.4.0
25
+
26
+ - Now we make diff to discover removed and added examples;
27
+
28
+ ## v0.3.0
29
+
30
+ - Removed and added files now is considered on run;
31
+
1
32
  ## v0.2.0
2
33
 
3
34
  - Splits specs by examples over files;
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,21 @@ 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`: Enables RSpeed
31
34
 
32
35
  ```sh
33
- RSPEED=true RSPEED_PIPES=3 RSPEED_PIPE=1 bundle exec rake rspeed:run
36
+ RSPEED=true RSPEED_NAME=authorizy RSPEED_PIPE=1 RSPEED_PIPES=3 bundle exec rake rspeed:run
34
37
  ```
35
38
 
36
39
  ## How it Works
37
40
 
38
41
  ### First run
39
42
 
40
- 1. Since we has no statistics on the first time, we run all specs and collect it;
43
+ 1. Since we have no statistics on the first time, we run all specs and collect it;
41
44
 
42
45
  ```json
43
46
  { "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
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpeed
4
- require 'csv'
5
- require 'redis'
4
+ require 'rspeed/env'
5
+ require 'rspeed/extension'
6
+ require 'rspeed/logger'
7
+ require 'rspeed/observer'
8
+ require 'rspeed/redis'
9
+ require 'rspeed/runner'
10
+ require 'rspeed/splitter'
11
+ require 'rspeed/variable'
6
12
  end
7
-
8
- require 'rspeed/extension'
9
- require 'rspeed/observer'
10
- require 'rspeed/runner'
11
- require 'rspeed/splitter'
data/lib/rspeed/env.rb ADDED
@@ -0,0 +1,39 @@
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
+ end
39
+ end
@@ -1,11 +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
7
  config.before(:suite) { RSpeed::Observer.before_suite }
8
8
  config.before { |example| RSpeed::Observer.before(example) }
9
9
  config.after { |example| RSpeed::Observer.after(example) }
10
+ config.after(:suite) { RSpeed::Observer.after_suite }
10
11
  end
11
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
@@ -9,9 +9,21 @@ module RSpeed
9
9
  line_number = example.metadata[:line_number]
10
10
  spent_time = example.clock.now - example.metadata[:start_at]
11
11
 
12
- File.open('rspeed.csv', 'a') do |file|
13
- file.write "#{spent_time},#{file_path}:#{line_number}\n"
14
- end
12
+ json = { file: "#{file_path}:#{line_number}", time: spent_time }.to_json
13
+
14
+ RSpeed::Redis.client.lpush(RSpeed::Variable.profile, json)
15
+ end
16
+
17
+ def after_suite(splitter = ::RSpeed::Splitter.new)
18
+ RSpeed::Redis.set(RSpeed::Variable.pipe_name, true)
19
+
20
+ return unless RSpeed::Redis.specs_finished?
21
+
22
+ splitter.rename
23
+
24
+ RSpeed::Redis.clean
25
+
26
+ RSpeed::Logger.log('RSpeed finished.')
15
27
  end
16
28
 
17
29
  def before(example)
@@ -19,11 +31,14 @@ module RSpeed
19
31
  end
20
32
 
21
33
  def before_suite
22
- truncate_csv_file
34
+ clean_profile
23
35
  end
24
36
 
25
- def truncate_csv_file
26
- File.open('rspeed.csv', 'w') { |file| file.truncate(0) }
37
+ def clean_profile
38
+ RSpeed::Logger.log('[RSpeed::Observer#clean_profile] Cleanning current flag and profile.')
39
+
40
+ RSpeed::Redis.destroy(RSpeed::Variable.pipe_name)
41
+ RSpeed::Redis.destroy(RSpeed::Variable.profile)
27
42
  end
28
43
  end
29
44
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Redis
5
+ require 'redis'
6
+
7
+ module_function
8
+
9
+ def clean
10
+ RSpeed::Logger.log('[RSpeed::Redis#clean] Cleaning pipes and profiles.')
11
+
12
+ destroy(RSpeed::Variable::PIPES_PATTERN)
13
+ destroy(RSpeed::Variable::PROFILE_PATTERN)
14
+ end
15
+
16
+ def client
17
+ @client ||= ::Redis.new(db: RSpeed::Env.db, host: RSpeed::Env.host, port: RSpeed::Env.port)
18
+ end
19
+
20
+ def destroy(pattern = RSpeed::Variable::DEFAULT_PATTERN)
21
+ RSpeed::Logger.log(%([RSpeed::Redis#destroy] Destroying pattern "#{pattern}".))
22
+
23
+ keys(pattern).each { |key| client.del(key) }
24
+ end
25
+
26
+ def get(key)
27
+ client.get(key)
28
+ end
29
+
30
+ def keys(pattern = RSpeed::Variable::DEFAULT_PATTERN)
31
+ cursor = 0
32
+ result = []
33
+
34
+ loop do
35
+ cursor, results = client.scan(cursor, match: pattern)
36
+ result += results
37
+
38
+ break if cursor.to_i.zero?
39
+ end
40
+
41
+ result
42
+ end
43
+
44
+ def result?
45
+ keys(RSpeed::Env.result_key).any?
46
+ end
47
+
48
+ def set(key, value)
49
+ client.set(key, value)
50
+ end
51
+
52
+ def specs_finished?
53
+ (RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).size == RSpeed::Env.pipes).tap do |boo|
54
+ RSpeed::Logger.log("[RSpeed::Redis#specs_finished?] Specs #{boo ? 'finished.' : 'not fineshed yet.'}")
55
+ end
56
+ end
57
+
58
+ def specs_initiated?
59
+ RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).any?.tap do |boo|
60
+ RSpeed::Logger.log("[RSpeed::Redis#specs_initiated?] Specs #{boo ? 'initialized.' : 'not initialized yet.'}")
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/rspeed/runner.rb CHANGED
@@ -4,25 +4,14 @@ module RSpeed
4
4
  module Runner
5
5
  module_function
6
6
 
7
- def run(shell)
8
- splitter = ::RSpeed::Splitter.new
9
-
10
- if splitter.first_pipe?
11
- # splitter.destroy "rspeed_*"
12
- splitter.destroy 'rspeed_tmp'
7
+ def run(shell, splitter: ::RSpeed::Splitter.new)
8
+ if RSpeed::Redis.result? || splitter.first_pipe?
9
+ return shell.call(['bundle exec rspec', splitter.pipe_files].compact.join(' '))
13
10
  end
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
12
+ RSpeed::Logger.log("Pipe #{RSpeed::Env.pipe} skipped. Only Pipe 1 can warm.")
24
13
 
25
- splitter.rename if splitter.last_pipe?
14
+ RSpeed::Observer.after_suite
26
15
  end
27
16
  end
28
17
  end
@@ -2,89 +2,92 @@
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
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].sort.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 /^it/.match?(item.gsub(/\s+/, ''))
20
+ end
21
+ end
22
+
23
+ stream(:actual_examples, examples)
24
+ end
10
25
  end
11
26
  end
12
27
 
13
- def destroy(pattern = DEFAULT_PATTERN)
14
- keys(pattern).each { |key| redis.del key }
28
+ def append?
29
+ RSpeed::Redis.result? || first_pipe?
30
+ end
31
+
32
+ def append(items:, key:)
33
+ items.each { |item| redis.rpush(key, item) }
15
34
  end
16
35
 
17
36
  def diff
18
- (actual_files + added_files).sort_by { |item| item[:time].to_f }.map do |item|
19
- [item[:time], item[:file]]
20
- end
37
+ actual_data = rspeed_data.select { |item| actual_examples.include?(item[:file]) }
38
+ added_data = added_examples.map { |item| { file: item, time: 0 } }
39
+
40
+ removed_examples # called just for stream for now
41
+
42
+ actual_data + added_data
21
43
  end
22
44
 
23
45
  def first_pipe?
24
- pipe == 1
46
+ RSpeed::Env.pipe == 1
25
47
  end
26
48
 
27
49
  def get(pattern)
28
50
  @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
- end
33
- end
51
+ return redis.lrange(pattern, 0, -1) if [RSpeed::Variable.result].include?(pattern)
34
52
 
35
- def keys(pattern = DEFAULT_PATTERN)
36
- cursor = 0
37
- result = []
38
-
39
- loop do
40
- cursor, results = redis.scan(cursor, match: pattern)
41
- result += results
42
-
43
- break if cursor.to_i.zero?
53
+ RSpeed::Redis.keys(pattern).map { |key| ::JSON.parse(redis.get(key)) }
44
54
  end
45
-
46
- result
47
55
  end
48
56
 
49
- def last_pipe?
50
- pipe == pipes
57
+ def need_warm?
58
+ first_pipe? && !RSpeed::Redis.result?
51
59
  end
52
60
 
53
- def pipe
54
- ENV.fetch('RSPEED_PIPE') { 1 }.to_i
55
- end
61
+ def pipe_files
62
+ return unless RSpeed::Redis.result?
56
63
 
57
- def pipes
58
- result? ? ENV.fetch('RSPEED_PIPES') { 1 }.to_i : 1
64
+ split[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].map { |item| item[:file] }.join(' ')
59
65
  end
60
66
 
61
67
  def rename
62
- redis.rename 'rspeed_tmp', 'rspeed'
63
- end
68
+ RSpeed::Logger.log('[RSpeed::Splitter#consolidate] Consolidating profiles.')
64
69
 
65
- def result?
66
- !keys('rspeed').empty?
67
- end
70
+ RSpeed::Redis.destroy(RSpeed::Env.result_key)
68
71
 
69
- def save(data = rspeed_data)
70
- split(data).each do |key, value|
71
- redis.set key, value.to_json
72
- end
72
+ append(
73
+ items: RSpeed::Redis.client.keys('rspeed_profile_*').map { |key| redis.lrange(key, 0, -1) },
74
+ key: RSpeed::Env.result_key
75
+ )
73
76
  end
74
77
 
75
- def split(data)
78
+ def split(data = diff)
76
79
  json = {}
77
80
 
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 }
81
+ RSpeed::Env.pipes.times do |index|
82
+ json[RSpeed::Variable.key(index + 1)] ||= []
83
+ json[RSpeed::Variable.key(index + 1)] = { total: 0, files: [], number: index + 1 }
81
84
  end
82
85
 
83
86
  sorted_data = data.sort_by { |item| item[:time] }.reverse
84
87
 
85
88
  sorted_data.each do |record|
86
89
  selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
87
- selected_pipe = json["rspeed_#{selected_pipe_data[1][:number]}".to_sym]
90
+ selected_pipe = json[RSpeed::Variable.key(selected_pipe_data[1][:number])]
88
91
  time = record[:time].to_f
89
92
 
90
93
  selected_pipe[:total] += time
@@ -96,44 +99,36 @@ module RSpeed
96
99
 
97
100
  private
98
101
 
99
- def actual_files
100
- rspeed_data.select { |item| actual_specs.include?(item[:file]) }
101
- end
102
-
103
- def actual_specs
104
- Dir['./spec/**/*_spec.rb']
105
- end
106
-
107
- def added_files
108
- added_specs.map { |item| { file: item, time: 0 } }
109
- end
110
-
111
- def added_specs
112
- actual_specs - saved_specs
113
- end
114
-
115
- def file_data
116
- CSV.read('rspeed.csv')
102
+ def added_examples
103
+ @added_examples ||= begin
104
+ (actual_examples - rspeed_examples).tap { |examples| stream(:added_examples, examples) }
105
+ end
117
106
  end
118
107
 
119
108
  def redis
120
- @redis ||= ::Redis.new(db: ENV['RSPEED_DB'], host: ENV['RSPEED_HOST'], port: ENV.fetch('RSPEED_PORT') { 6379 })
109
+ @redis ||= ::RSpeed::Redis.client
121
110
  end
122
111
 
123
- def removed_specs
124
- saved_specs - actual_specs
112
+ def removed_examples
113
+ @removed_examples ||= begin
114
+ (rspeed_examples - actual_examples).tap { |examples| stream(:removed_examples, examples) }
115
+ end
125
116
  end
126
117
 
127
118
  def removed_time
128
- removed_specs.map { |item| item[0].to_f }.sum
119
+ removed_examples.sum { |item| item[0].to_f }
129
120
  end
130
121
 
131
122
  def rspeed_data
132
- get('rspeed').map { |item| JSON.parse item, symbolize_names: true }
123
+ @rspeed_data ||= get(RSpeed::Env.result_key).map { |item| JSON.parse(item, symbolize_names: true) }
133
124
  end
134
125
 
135
- def saved_specs
126
+ def rspeed_examples
136
127
  rspeed_data.map { |item| item[:file] }
137
128
  end
129
+
130
+ def stream(type, data)
131
+ RSpeed::Logger.log("PIPE: #{RSpeed::Env.pipe} with #{type}: #{data}")
132
+ end
138
133
  end
139
134
  end