rspec-big-split 0.1.0 → 0.3.1

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: a1d3cf217b11c3eb3f3c55e2a5b72b7189d872f329da515628059f7d1ffa3f7c
4
- data.tar.gz: ccb04637123dc99fdd8fa723e17458fc1340fc956206a93b9425beabc48cf31e
3
+ metadata.gz: 20f5e4c2f972d26054fa30ca2788fcd8047a9b06044d7ce3e6819517a766cca3
4
+ data.tar.gz: ccba4e1c22c523c049ead08e59d9bc42fd282ed3e975c7d7cea3a21fec0500fa
5
5
  SHA512:
6
- metadata.gz: aabcdae89d712a55daef97a81933b568edaa71955e7b1cf3e838b8be074fbfb21fea5c3145822ca1bb52ec8691a30a79404aa3361e6410eec5759b6f4510b223
7
- data.tar.gz: d00bd6b3b5f8c77fc6e9980ecf67fa05428e76484f3fd01847daf437a5245c8312e83c8f521ce82f25f3df4d29ab6a2c95d637fe77699e74da27574bbf70bee5
6
+ metadata.gz: d8cf84fa84d023337a0ac541344ea317db3877b57c6fe3947cc13ba90bf4ef09917872137687e8543eb2d84462972414dbd678c59a5a431709aee582bc20dc4e
7
+ data.tar.gz: 3be4b0b93b25f3a53cb41d06e305292e1855c6420f0e2f9ab62938ddc20d7288a57c4a9974273f8acdc572fb910738d4280574717946068695ac9dda38b6d5a7
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 iPePe.pl Open Source Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -6,30 +6,17 @@ TODO: Delete this and the text above, and describe your gem
6
6
 
7
7
  ## Installation
8
8
 
9
- Add this line to your application's Gemfile:
9
+ Execute this command to add gem to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'rspec-big-split'
12
+ bundle add rspec-big-split
13
13
  ```
14
14
 
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install rspec-big-split
22
-
23
15
  ## Usage
24
16
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-big-split.
17
+ 1. Add `ci_split_example_groups: true` as metadata to your example groups (only for big files).
18
+ 2. Generate tests map with: `bundle exec rspec --dry-run --format Rspec::Big::Split::Formatter --out tmp/rspec_splitter.json`
19
+ 3. Define variables like `TEST_NODE_TOTAL=20` and `TEST_NODE_INDEX=0` in your CI/CD configuration.
20
+ * Make sure that your indexing starts with `1` and ends equal to `TEST_NODE_TOTAL`.
21
+ 4. (optional) Printout tests that will be run in current node: `bundle exec rspec-big-split tmp/rspec_splitter.json`
22
+ 5. Run tests with `bundle exec rspec $(bundle exec rspec-big-split tmp/rspec_splitter.json)` to run tests on each node.
@@ -0,0 +1,45 @@
1
+ #!/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+
6
+ total_workers = ENV.fetch("TEST_NODE_TOTAL", "1").to_i
7
+ this_worker_index = ENV.fetch("TEST_NODE_INDEX", "1").to_i
8
+
9
+ warn "TEST_NODE_TOTAL=#{total_workers}"
10
+ warn "TEST_NODE_INDEX=#{this_worker_index}"
11
+
12
+ raise "TEST_NODE_INDEX must be between 1 and TEST_NODE_TOTAL" unless (1..total_workers).cover?(this_worker_index)
13
+
14
+ # Load the examples from the JSON file
15
+ if ARGV[0]
16
+ path = ARGV[0]
17
+ all_rspec_examples = JSON.parse(File.read(path))["examples"]
18
+
19
+ example_paths = {}
20
+
21
+ all_rspec_examples.map do |example|
22
+ if example["ci_split_example_groups"] || ARGV.include?("--split-by-example")
23
+ example_paths[example["id"]] ||= []
24
+ example_paths[example["id"]].push example["id"]
25
+ else
26
+ example_paths[example["file_path"]] ||= []
27
+ example_paths[example["file_path"]].push example["id"]
28
+ end
29
+ end
30
+
31
+ # Split the examples into groups
32
+ examples_to_run_for_current_worker = []
33
+ example_paths.keys.sort.each_with_index do |example, index|
34
+ next unless ((index % total_workers) - 1) == this_worker_index
35
+
36
+ examples_to_run_for_current_worker.concat(
37
+ example_paths[example]
38
+ )
39
+ end
40
+ warn "Suggesting #{examples_to_run_for_current_worker.size}/#{example_paths.size} examples on worker #{this_worker_index}"
41
+ $stdout.puts examples_to_run_for_current_worker
42
+ else
43
+ warn "Usage: rspec-big-split <path to JSON file>"
44
+ exit 1
45
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core/formatters/json_formatter"
4
+
5
+ module Rspec
6
+ module Big
7
+ module Split
8
+ class Formatter < ::RSpec::Core::Formatters::JsonFormatter
9
+ ::RSpec::Core::Formatters.register self
10
+
11
+ private
12
+
13
+ def format_example(example)
14
+ {
15
+ id: example.id,
16
+ ci_split_example_groups: example.metadata[:ci_split_example_groups],
17
+ example_group_id: example.example_group.id
18
+ }.merge(super.slice(:file_path))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,7 +3,7 @@
3
3
  module Rspec
4
4
  module Big
5
5
  module Split
6
- VERSION = "0.1.0"
6
+ VERSION = "0.3.1"
7
7
  end
8
8
  end
9
9
  end
@@ -1,12 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "split/version"
4
-
5
- module Rspec
6
- module Big
7
- module Split
8
- class Error < StandardError; end
9
- # Your code goes here...
10
- end
11
- end
12
- end
4
+ require_relative "split/formatter"
@@ -24,11 +24,11 @@ Gem::Specification.new do |spec|
24
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
25
  end
26
26
  spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.executables = ["rspec-big-split"]
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  # Uncomment to register a new dependency of your gem
31
- # spec.add_dependency "example-gem", "~> 1.0"
31
+ spec.add_dependency "rspec-core", "~> 3"
32
32
 
33
33
  # For more information and examples about making a new gem, checkout our
34
34
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,19 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-big-split
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patryk Ptasinski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-05 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2024-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ description:
14
28
  email:
15
29
  - patryk@ipepe.pl
16
- executables: []
30
+ executables:
31
+ - rspec-big-split
17
32
  extensions: []
18
33
  extra_rdoc_files: []
19
34
  files:
@@ -22,11 +37,14 @@ files:
22
37
  - ".rubocop.yml"
23
38
  - CHANGELOG.md
24
39
  - Gemfile
40
+ - LICENSE
25
41
  - README.md
26
42
  - Rakefile
27
43
  - bin/console
28
44
  - bin/setup
45
+ - exe/rspec-big-split
29
46
  - lib/rspec/big/split.rb
47
+ - lib/rspec/big/split/formatter.rb
30
48
  - lib/rspec/big/split/version.rb
31
49
  - publish.sh
32
50
  - rspec-big-split.gemspec
@@ -37,7 +55,7 @@ metadata:
37
55
  homepage_uri: https://github.com/ipepe-oss/rspec-big-split
38
56
  source_code_uri: https://github.com/ipepe-oss/rspec-big-split
39
57
  changelog_uri: https://github.com/ipepe-oss/rspec-big-split
40
- post_install_message:
58
+ post_install_message:
41
59
  rdoc_options: []
42
60
  require_paths:
43
61
  - lib
@@ -52,9 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
70
  - !ruby/object:Gem::Version
53
71
  version: '0'
54
72
  requirements: []
55
- rubyforge_project:
56
- rubygems_version: 2.7.6.2
57
- signing_key:
73
+ rubygems_version: 3.1.6
74
+ signing_key:
58
75
  specification_version: 4
59
76
  summary: Split one big RSpec test file into many smaller ones for parallel execution
60
77
  test_files: []