rspec_chunked 0.3 → 0.5

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: 269d7677063d252032ed8e26c4d0b469417ba5e2bab2cc868edc79176f8201f9
4
- data.tar.gz: 2ee7a9c1e3b51809ac8f7e3312bf806acbebc049be0d21f80686636aa99a8c6b
3
+ metadata.gz: cc398c99a740b44f4503b351d0161a93db59a2ee50a87ce992d7863faf00278c
4
+ data.tar.gz: ac9a9e3cd8bd6dd05d4d20c191e8d59efba116a37be3f0fe8948e4267e11542d
5
5
  SHA512:
6
- metadata.gz: 6a7d86038a73855d043f69a134aa11e7a5aebcff4ad88d4dd5cc39d8d269bef8dd64a9c1a85bccd7e765ed522aa10056400c0d5e0f362d6631093c302517ae6d
7
- data.tar.gz: 8103b9cc56f2fb35674789dfae0d44c41553c22f511a44cbdd9ae325ab099143be811edcc99534ad9b674ffca179882c64bbe8bcf8893b2cd1cb232ca5b2fa57
6
+ metadata.gz: 533b28d0ddf8b52d6502527889364fa80537fcfb1e0d5aec1406030b408cff5f98cdf3517b8795f410969cef87c1e509137a6f33a28869bbded20341f4a660e8
7
+ data.tar.gz: 5f40aa1988ce2b4350ffcc7e9e065617df4533bf37ad101ff8efab95944a53a6796d807463459ef2ac132dcf0069eb6f63bb99e3e91bdc906bda4162a3ea3f7d
data/README.md CHANGED
@@ -15,7 +15,7 @@ If ordering is not enough, permits to balance manually by moving x percentage of
15
15
 
16
16
  - Add manual balance
17
17
  ```ruby
18
- # config/initializers/rspec_chunked.rb
18
+ # config/rspec_chunked.rb
19
19
  if defined?(RspecChunked::ChunkedTests)
20
20
  data = { 1 => { to: 2, percentage: 15 },
21
21
  4 => { to: 3, percentage: 10 } }
@@ -25,9 +25,17 @@ If ordering is not enough, permits to balance manually by moving x percentage of
25
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
26
26
 
27
27
  ## Usage
28
- ` CI_JOBS=3 CI_JOB=1 rake rspec_chunked `
29
- - `CI_JOBS`: quantity of groups/workers to be split
30
- - `CI_JOB`: current group/worker to be executed, limit: 1 until CI_JOBS
28
+ - Basic initialization
29
+ ` CI_JOBS=1/3 rake rspec_chunked`
30
+ - Custom initialization
31
+ ` CI_JOBS=1/3 CI_CMD="bundle exec rspec ..." rake rspec_chunked`
32
+ - `CI_JOBS`: Current job number / quantity of groups/jobs to be split
33
+ - `CI_CMD`: Custom rspec command
34
+
35
+ ### Coverage merge reports (when using [simplecov](https://github.com/simplecov-ruby/simplecov#merging-test-runs-under-different-execution-environments))
36
+ This task will merge all coverage reports
37
+ `rake rspec_chunked:merge_reports`
38
+
31
39
 
32
40
  ### Github workflow result
33
41
  - Before:
@@ -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.abort('failed running command') unless Kernel.system "#{cmd} #{tests.join(' ')}"
22
23
  end
23
24
 
24
25
  private
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rspec_chunked'
3
4
  require 'rails'
5
+
4
6
  module RspecChunked
5
- class Railtie < ::Rails::Railtie
7
+ class Railtie < Rails::Railtie
8
+ railtie_name :my_gem
9
+
6
10
  rake_tasks do
7
11
  load 'tasks/rspec_chunked_tasks.rake'
8
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecChunked
4
- VERSION = '0.3'
4
+ VERSION = '0.5'
5
5
  end
@@ -1,10 +1,28 @@
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: :environment do
5
- qty_jobs = (ENV['CI_JOBS'] || 3).to_i
6
- job_number = (ENV['CI_JOB'] || 1).to_i
7
-
8
- service = RspecChunked::ChunkedTests.new(qty_jobs, job_number)
4
+ task :rspec_chunked do
5
+ job_number, qty_jobs = (ENV['CI_JOBS'] || '1/3').split('/')
6
+ load_config
7
+ service = RspecChunked::ChunkedTests.new(qty_jobs.to_i, job_number.to_i, cmd: ENV['CI_CMD'])
9
8
  service.run
9
+ copy_coverage(job_number)
10
+ end
11
+
12
+ def load_config
13
+ config_file = File.join(Dir.pwd, 'config', 'rspec_chunked.rb')
14
+ load config_file if File.exist?(config_file)
15
+ end
16
+
17
+ def copy_coverage(job_number)
18
+ path = 'coverage/.resultset.json'
19
+ FileUtils.cp path, "coverage/.resultset-#{job_number}.json" if File.exist?(path)
20
+ end
21
+
22
+ namespace :rspec_chunked do
23
+ desc 'Collates all result sets generated by the different test runners'
24
+ task :merge_reports do
25
+ require 'simplecov'
26
+ SimpleCov.collate Dir['coverage/.resultset-*']
27
+ end
10
28
  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.3'
4
+ version: '0.5'
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-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler