rspec_chunked 0.1.0 → 0.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76485af77917941cf4e9afbc37c5580077bb3943fb1b9bebdaa5c9ae3c83c8f4
4
- data.tar.gz: 814d02ffe139f175ae2c2ef8bb2b64d14b8c8407ee37d381fcc00c333b072ee6
3
+ metadata.gz: a22a1dad0fb805db73f6d53b2a9b19894a08b7c4b299de78a63e9bd88015ab6f
4
+ data.tar.gz: dde3ab891cdb771964db3ea58922836fae874e969a0ca86fb3b41ecc4dce20a0
5
5
  SHA512:
6
- metadata.gz: 87c877e3ef437d78d6dda51fa63e1c4168c046731891c587ff50db107778a24535427536d885d9f576aa016f10b8fdb91b42062ab9545df7bcbe9fdc4670562a
7
- data.tar.gz: b0e7f004c432ada92eb8ed2997626e62f8c65ec7b3331af1d98a4d879481e460a05387a5cfcb5fcaadb275e9481193def45aa8cc7c36a38357735da05a322d35
6
+ metadata.gz: bee4a8e04ecfb698edb4b462a658f03fb13c8b0e1500fc9d68c7234af468bfc645706a66a0036908c29e09742431f3ff43472600f26dd617d2ecd4ce5db20008
7
+ data.tar.gz: a5993d30cd9f60bad63761021dbba113cb7ec3addddd5ebc756bbbded12e6b635d264498aa98c3f1027f0437ad1661f5db9ee18f020cf5d7e1e5abda004c1a4f
data/README.md CHANGED
@@ -16,23 +16,34 @@ If ordering is not enough, permits to balance manually by moving x percentage of
16
16
  - Add manual balance
17
17
  ```ruby
18
18
  # config/initializers/rspec_chunked.rb
19
- return unless defined?(RspecChunked::ChunkedTests)
20
-
21
- RspecChunked::ChunkedTests.balance_settings = { 1 => { to: 2, percentage: 15 }, 4 => { to: 3, percentage: 10 } }
19
+ if defined?(RspecChunked::ChunkedTests)
20
+ data = { 1 => { to: 2, percentage: 15 },
21
+ 4 => { to: 3, percentage: 10 } }
22
+ RspecChunked::ChunkedTests.balance_settings = data
23
+ end
22
24
  ```
23
25
  Balance tests by moving 15% tests files from group 1 into group 2 and moving 10% tests files from group 4 into group 3
24
26
 
25
27
  ## Usage
26
- ` CI_JOBS=3 CI_JOB=1 rake rspec_chunked `
28
+ - Basic initialization
29
+ ` CI_JOBS=3 CI_JOB=1 rake rspec_chunked`
30
+ - Custom initialization
31
+ ` CI_JOBS=3 CI_JOB=1 CI_CMD="bundle exec rspec ..." rake rspec_chunked`
27
32
  - `CI_JOBS`: quantity of groups/workers to be split
28
33
  - `CI_JOB`: current group/worker to be executed, limit: 1 until CI_JOBS
34
+ - `CI_CMD`: Custom rspec command
35
+
36
+ ### Coverage merge reports (when using [simplecov](https://github.com/simplecov-ruby/simplecov#merging-test-runs-under-different-execution-environments))
37
+ This task will merge all coverage reports
38
+ `rake rspec_chunked:merge_reports`
39
+
29
40
 
30
41
  ### Github workflow result
31
42
  - Before:
32
43
  ![Before](/docs/before.png?raw=true)
33
44
 
34
- - Current:
35
- ![Current](/docs/current.png?raw=true)
45
+ - After:
46
+ ![After](/docs/current.png?raw=true)
36
47
 
37
48
  - Github workflow sample:
38
49
  ````yaml
data/Rakefile CHANGED
@@ -25,3 +25,7 @@ Rake::TestTask.new(:test) do |t|
25
25
  end
26
26
 
27
27
  task default: :test
28
+
29
+ # gem tasks
30
+ path = File.expand_path(__dir__)
31
+ Dir.glob("#{path}/lib/tasks/**/*.rake").each { |f| import f }
data/lib/rspec_chunked.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rspec_chunked/railtie' if defined?(Rails)
3
4
  require 'rspec_chunked/chunked_tests'
4
5
  module RspecChunked
5
6
  end
@@ -5,12 +5,13 @@ module RspecChunked
5
5
  class << self
6
6
  attr_accessor :balance_settings
7
7
  end
8
- attr_accessor :qty_groups, :job_number, :balance_settings
8
+ attr_accessor :qty_groups, :job_number, :balance_settings, :cmd
9
9
 
10
- def initialize(qty_groups, job_number)
10
+ def initialize(qty_groups, job_number, cmd: nil)
11
11
  @qty_groups = qty_groups
12
12
  @job_number = job_number - 1
13
13
  @balance_settings = self.class.balance_settings || {}
14
+ @cmd = cmd || 'bundle exec rspec'
14
15
  end
15
16
 
16
17
  def run
@@ -18,7 +19,7 @@ module RspecChunked
18
19
  tests = balanced_tests[job_number]
19
20
  qty = balanced_tests.flatten.count
20
21
  Kernel.puts "**** running #{tests.count}/#{qty} tests (group number: #{job_number + 1})"
21
- Kernel.exec "bundle exec rspec #{tests.join(' ')}"
22
+ Kernel.exec "#{cmd} #{tests.join(' ')}"
22
23
  end
23
24
 
24
25
  private
@@ -35,7 +36,7 @@ module RspecChunked
35
36
 
36
37
  def test_files
37
38
  Dir['spec/**/*_spec.rb'].sort_by do |path|
38
- File.size(File.join(__dir__, '../', path)).to_f
39
+ File.size(File.join('./', path)).to_f
39
40
  end
40
41
  end
41
42
 
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rails'
3
4
  module RspecChunked
4
5
  class Railtie < ::Rails::Railtie
6
+ rake_tasks do
7
+ load 'tasks/rspec_chunked_tasks.rake'
8
+ end
5
9
  end
6
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecChunked
4
- VERSION = '0.1.0'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -1,10 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  desc 'Run chunked rspec tests on specific qty, sample: CI_JOBS=3 CI_JOB=1 rake rspec_chunked'
4
- task :rspec_chunked do
4
+ task rspec_chunked: :environment do
5
5
  qty_jobs = (ENV['CI_JOBS'] || 3).to_i
6
6
  job_number = (ENV['CI_JOB'] || 1).to_i
7
-
8
- service = RspecChunked::ChunkedTests.new(qty_jobs, job_number)
7
+ service = RspecChunked::ChunkedTests.new(qty_jobs, job_number, cmd: ENV['CI_CMD'])
9
8
  service.run
9
+ copy_coverage(job_number)
10
+ end
11
+
12
+ def copy_coverage(job_number)
13
+ path = 'coverage/.resultset.json'
14
+ FileUtils.cp path, "coverage/.resultset-#{job_number}.json" if File.exist?(path)
15
+ end
16
+
17
+ namespace :rspec_chunked do
18
+ desc 'Collates all result sets generated by the different test runners'
19
+ task :merge_reports do
20
+ require 'simplecov'
21
+ SimpleCov.collate Dir['coverage/.resultset-*']
22
+ end
10
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_chunked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - owen2345
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler