rspec_chunked 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc398c99a740b44f4503b351d0161a93db59a2ee50a87ce992d7863faf00278c
4
- data.tar.gz: ac9a9e3cd8bd6dd05d4d20c191e8d59efba116a37be3f0fe8948e4267e11542d
3
+ metadata.gz: 126bfb5e31cdc7fc519a21d3b040bc6ff34227bbd55059cd3a195f1ef3575ea5
4
+ data.tar.gz: b5f82ce322ec832bc8acbd7022098a559adc93c4a309829e1f1801b2913180a5
5
5
  SHA512:
6
- metadata.gz: 533b28d0ddf8b52d6502527889364fa80537fcfb1e0d5aec1406030b408cff5f98cdf3517b8795f410969cef87c1e509137a6f33a28869bbded20341f4a660e8
7
- data.tar.gz: 5f40aa1988ce2b4350ffcc7e9e065617df4533bf37ad101ff8efab95944a53a6796d807463459ef2ac132dcf0069eb6f63bb99e3e91bdc906bda4162a3ea3f7d
6
+ metadata.gz: 264adcb2b6c8e52695240a7797c49a0406e915200eee2aecafef532662cf375249d1b9f1b18aa92b5194e140eef299b0f88b1bbbe49e621882724a68a657b79a
7
+ data.tar.gz: e652f96bec6139ac8fc03951333da1acdd3eab1f0d8eb4a2d88cc61ac7446adc8277b9f7d31f3c1de440dec8f998fc7d98abdf672e227e0b14eb07504bd4364f
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # RspecChunked
2
- This gem permits to run rspec tests in parallel by chunking tests into defined groups and balancing by file size.
3
- If ordering is not enough, permits to balance manually by moving x percentage of tests files from group A into group B.
2
+ This gem permits running rspec tests in parallel by chunking tests into defined groups and balancing by file size. If the default order is not enough, it permits to balance manually by moving x percentage of test files from group A into group B.
4
3
 
5
4
  ## Installation
6
5
  - Add this line to your application's Gemfile:
@@ -13,24 +12,25 @@ If ordering is not enough, permits to balance manually by moving x percentage of
13
12
  - And then execute:
14
13
  `bundle install`
15
14
 
16
- - Add manual balance
17
- ```ruby
18
- # config/rspec_chunked.rb
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
24
- ```
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
15
+ - Add manual balance (optional)
16
+ ```ruby
17
+ # config/rspec_chunked.rb
18
+ if defined?(RspecChunked::ChunkedTests)
19
+ data = { 1 => { to: 2, percentage: 15 },
20
+ 4 => { to: 3, percentage: 10 } }
21
+ RspecChunked::ChunkedTests.balance_settings = data
22
+ end
23
+ ```
24
+ 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
25
 
27
26
  ## Usage
28
27
  - Basic initialization
29
28
  ` CI_JOBS=1/3 rake rspec_chunked`
30
29
  - Custom initialization
31
- ` CI_JOBS=1/3 CI_CMD="bundle exec rspec ..." rake rspec_chunked`
30
+ ` CI_LOGIC=qty_specs CI_JOBS=1/3 CI_CMD="bundle exec rspec ..." rake rspec_chunked`
32
31
  - `CI_JOBS`: Current job number / quantity of groups/jobs to be split
33
32
  - `CI_CMD`: Custom rspec command
33
+ - `CI_LOGIC`: Kind of logic to be used when ordering tests: `qty_specs` or `file_size` (by default `file_size`)
34
34
 
35
35
  ### Coverage merge reports (when using [simplecov](https://github.com/simplecov-ruby/simplecov#merging-test-runs-under-different-execution-environments))
36
36
  This task will merge all coverage reports
@@ -54,14 +54,12 @@ This task will merge all coverage reports
54
54
  matrix:
55
55
  ci_job: [ 1, 2, 3, 4 ] # enumerize jobs
56
56
  env:
57
- CI_JOBS: 4 # define total jobs (must match with matrix above)
57
+ CI_JOBS: ${{ matrix.ci_job }}/4 # <current_job>/<total_jobs>
58
58
 
59
59
  steps:
60
60
  - uses: actions/checkout@v2
61
61
  - name: Backend tests
62
- env:
63
- CI_JOB: ${{ matrix.ci_job }}
64
- run: docker-compose run test /bin/sh -c "CI_JOBS=$CI_JOBS CI_JOB=$CI_JOB rake rspec_chunked"
62
+ run: docker-compose run test /bin/sh -c "CI_JOBS=$CI_JOBS rake rspec_chunked"
65
63
 
66
64
  ````
67
65
 
@@ -5,11 +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, :cmd
8
+ attr_accessor :qty_groups, :job_number, :balance_settings, :cmd, :order_logic
9
9
 
10
- def initialize(qty_groups, job_number, cmd: nil)
10
+ # @param order_logic (:qty_specs|:file_size*)
11
+ def initialize(qty_groups, job_number, cmd: nil, order_logic: :file_size)
11
12
  @qty_groups = qty_groups
12
13
  @job_number = job_number - 1
14
+ @order_logic = order_logic
13
15
  @balance_settings = self.class.balance_settings || {}
14
16
  @cmd = cmd || 'bundle exec rspec'
15
17
  end
@@ -18,7 +20,7 @@ module RspecChunked
18
20
  balanced_tests = balance_tests(group_tests, balance_settings)
19
21
  tests = balanced_tests[job_number]
20
22
  qty = balanced_tests.flatten.count
21
- Kernel.puts "**** running #{tests.count}/#{qty} tests (group number: #{job_number + 1})"
23
+ Kernel.puts "**** running #{tests.count}/#{qty} test files (group number: #{job_number + 1})"
22
24
  Kernel.abort('failed running command') unless Kernel.system "#{cmd} #{tests.join(' ')}"
23
25
  end
24
26
 
@@ -36,10 +38,19 @@ module RspecChunked
36
38
 
37
39
  def test_files
38
40
  Dir['spec/**/*_spec.rb'].sort_by do |path|
39
- File.size(File.join('./', path)).to_f
41
+ if order_logic == :qty_specs
42
+ count_specs_for(path)
43
+ else
44
+ File.size(File.join('./', path)).to_f
45
+ end
40
46
  end
41
47
  end
42
48
 
49
+ def count_specs_for(path)
50
+ body = File.read(File.join('./', path))
51
+ body.scan(/ it ['|"]/).count
52
+ end
53
+
43
54
  # Balance tests by moving x percentage tests files from group 1 into group 2
44
55
  # Sample balance_tests(data, { 1 => { to: 2, percentage: 15 }, 3 => { to: 0, percentage: 10 } })
45
56
  # @return (Array) same array with balance applied tests
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecChunked
4
- VERSION = '0.5'
4
+ VERSION = '0.6'
5
5
  end
@@ -3,8 +3,10 @@
3
3
  desc 'Run chunked rspec tests on specific qty, sample: CI_JOBS=3 CI_JOB=1 rake rspec_chunked'
4
4
  task :rspec_chunked do
5
5
  job_number, qty_jobs = (ENV['CI_JOBS'] || '1/3').split('/')
6
+ logic = (ENV['CI_LOGIC'] || :file_size).to_sym
6
7
  load_config
7
- service = RspecChunked::ChunkedTests.new(qty_jobs.to_i, job_number.to_i, cmd: ENV['CI_CMD'])
8
+ service = RspecChunked::ChunkedTests.new(qty_jobs.to_i, job_number.to_i,
9
+ cmd: ENV['CI_CMD'], order_logic: logic)
8
10
  service.run
9
11
  copy_coverage(job_number)
10
12
  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.5'
4
+ version: '0.6'
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-27 00:00:00.000000000 Z
11
+ date: 2021-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler