parallel_rspec 0.5.0 → 2.1.1
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 +5 -5
- data/README.md +22 -3
- data/lib/parallel_rspec/client.rb +1 -0
- data/lib/parallel_rspec/config.rb +13 -0
- data/lib/parallel_rspec/example.rb +4 -2
- data/lib/parallel_rspec/railtie.rb +9 -6
- data/lib/parallel_rspec/runner.rb +7 -0
- data/lib/parallel_rspec/tasks.rake +37 -15
- data/lib/parallel_rspec/version.rb +1 -1
- data/lib/parallel_rspec/workers.rb +15 -2
- data/lib/parallel_rspec.rb +11 -0
- data/parallel_rspec.gemspec +2 -2
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 789b0fec42e9fe3b485305a5da250915fab02f89678dba1171ec7fd2d7b0bcc5
|
4
|
+
data.tar.gz: 259d48bbffa5177861d88cf92daa4a9b942e4d40d21dff4d04ee3eb190a49dde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5da7ba542f13faacb9d89906b23255c02262e228b3cfa4c72377f0f0a1addfabfcb1c6970e6c15316e4a569f4ed15b28592ce11b0cbad522b7342c67f97ed13
|
7
|
+
data.tar.gz: 4a1eac0dfaa95d8ef167380ec9922072dee901e2e9087c0c9f00b121b34dde73cd148dada9c435bf51d98cb5f6547eaf31f5aa61e9b9effa8de148843f7ee122
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ And then execute:
|
|
24
24
|
|
25
25
|
$ bundle
|
26
26
|
|
27
|
-
This version of ParallelRSpec has been tested with RSpec 3.
|
27
|
+
This version of ParallelRSpec has been tested with RSpec 3.10.
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
@@ -53,17 +53,35 @@ You may like to make an alias:
|
|
53
53
|
|
54
54
|
When you change WORKERS, don't forget to restart Spring and re-run the create and populate steps above if necessary.
|
55
55
|
|
56
|
-
|
56
|
+
By default, there's a task called `parallel_rspec` which will run all specs. To make a custom rake task which uses parallel_rspec with different options, inherit from ParallelRSpec::RakeTask, for example:
|
57
57
|
|
58
58
|
```ruby
|
59
|
+
require 'parallel_rspec'
|
60
|
+
|
59
61
|
ParallelRSpec::RakeTask.new(:prspec) do |t|
|
60
62
|
ENV['WORKERS'] = '4'
|
61
|
-
t.pattern = "
|
63
|
+
t.pattern = "spec/**/*_spec.rb"
|
62
64
|
t.rspec_opts = "--tag parallel"
|
63
65
|
# etc...
|
64
66
|
end
|
65
67
|
```
|
66
68
|
|
69
|
+
If you'd like code to run after parallel_rspec has created each worker, you can specify a block to run:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
ParallelRSpec.configure do |config|
|
73
|
+
config.after_fork do |worker_number|
|
74
|
+
puts "I am worker #{worker_number}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
You might also want to detect whether your spec suite is running under ParallelRSpec or not:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
do_something unless ParallelRSpec.running?
|
83
|
+
```
|
84
|
+
|
67
85
|
## Contributing
|
68
86
|
|
69
87
|
Bug reports and pull requests are welcome on GitHub at https://github.com/willbryant/parallel_rspec.
|
@@ -72,6 +90,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/willbr
|
|
72
90
|
## Thanks
|
73
91
|
|
74
92
|
* Charles Horn (@hornc)
|
93
|
+
* Roger Nesbitt (@mogest)
|
75
94
|
|
76
95
|
|
77
96
|
## License
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module ParallelRSpec
|
2
|
+
ExampleGroup = Struct.new(:parent_groups)
|
3
|
+
|
2
4
|
# only the good bits of RSpec's Example class, those needed by the reporters and formatters and
|
3
5
|
# marshallable.
|
4
|
-
Example = Struct.new(:id, :description, :exception, :location_rerun_argument, :metadata) do
|
6
|
+
Example = Struct.new(:id, :description, :exception, :location_rerun_argument, :example_group, :metadata) do
|
5
7
|
def self.delegate_to_metadata(key)
|
6
8
|
define_method(key) { metadata[key] }
|
7
9
|
end
|
@@ -13,4 +15,4 @@ module ParallelRSpec
|
|
13
15
|
delegate_to_metadata :pending
|
14
16
|
delegate_to_metadata :skip
|
15
17
|
end
|
16
|
-
end
|
18
|
+
end
|
@@ -1,11 +1,14 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'rails'
|
2
3
|
|
3
|
-
module ParallelRSpec
|
4
|
-
|
5
|
-
|
4
|
+
module ParallelRSpec
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
railtie_name :parallel_rspec
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
rake_tasks do
|
9
|
+
load "parallel_rspec/tasks.rake"
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
13
|
+
rescue LoadError
|
11
14
|
end
|
@@ -16,6 +16,12 @@ end
|
|
16
16
|
|
17
17
|
module ParallelRSpec
|
18
18
|
class Runner < RSpec::Core::Runner
|
19
|
+
@@running = false
|
20
|
+
|
21
|
+
def self.running?
|
22
|
+
@@running
|
23
|
+
end
|
24
|
+
|
19
25
|
# Runs the suite of specs and exits the process with an appropriate exit
|
20
26
|
# code.
|
21
27
|
def self.invoke
|
@@ -39,6 +45,7 @@ module ParallelRSpec
|
|
39
45
|
# or the configured failure exit code (1 by default) if specs
|
40
46
|
# failed.
|
41
47
|
def self.run(args, err=$stderr, out=$stdout)
|
48
|
+
@@running = true
|
42
49
|
RSpec::Core::Runner.trap_interrupt
|
43
50
|
options = RSpec::Core::ConfigurationOptions.new(args)
|
44
51
|
new(options).run(err, out)
|
@@ -2,27 +2,41 @@ require 'parallel_rspec/workers.rb'
|
|
2
2
|
|
3
3
|
db_namespace = namespace :db do
|
4
4
|
namespace :parallel do
|
5
|
-
|
5
|
+
desc "Creates the test databases"
|
6
6
|
task :create => [:load_config] do
|
7
7
|
ParallelRSpec::Workers.new.run_test_workers do |worker|
|
8
|
-
|
8
|
+
if ActiveRecord::Base.configurations.respond_to?(:configs_for)
|
9
|
+
ActiveRecord::Base.configurations.configs_for(env_name: 'test').each do |configuration|
|
10
|
+
ActiveRecord::Tasks::DatabaseTasks.create configuration
|
11
|
+
end
|
12
|
+
else
|
13
|
+
ActiveRecord::Tasks::DatabaseTasks.create ActiveRecord::Base.configurations['test']
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
|
12
|
-
|
18
|
+
desc "Empty the test databases"
|
13
19
|
task :purge => %w(environment load_config) do
|
14
20
|
ParallelRSpec::Workers.new.run_test_workers do |worker|
|
15
|
-
ActiveRecord::Tasks::DatabaseTasks.
|
21
|
+
if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:purge_current)
|
22
|
+
ActiveRecord::Tasks::DatabaseTasks.purge_current 'test'
|
23
|
+
else
|
24
|
+
ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations['test']
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
|
-
|
29
|
+
desc "Recreate the test databases from an existent schema.rb file"
|
20
30
|
task :load_schema => %w(db:parallel:purge) do
|
21
31
|
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
|
22
32
|
begin
|
23
33
|
ParallelRSpec::Workers.new.run_test_workers do |worker|
|
24
34
|
ActiveRecord::Schema.verbose = false
|
25
|
-
ActiveRecord::Tasks::DatabaseTasks.
|
35
|
+
if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:load_schema_current)
|
36
|
+
ActiveRecord::Tasks::DatabaseTasks.load_schema_current :ruby, ENV['SCHEMA'], 'test'
|
37
|
+
else
|
38
|
+
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
|
39
|
+
end
|
26
40
|
end
|
27
41
|
ensure
|
28
42
|
if should_reconnect
|
@@ -31,25 +45,29 @@ db_namespace = namespace :db do
|
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
34
|
-
|
48
|
+
desc "Recreate the test databases from an existent structure.sql file"
|
35
49
|
task :load_structure => %w(db:parallel:purge) do
|
36
50
|
ParallelRSpec::Workers.new.run_test_workers do |worker|
|
37
|
-
ActiveRecord::Tasks::DatabaseTasks.
|
51
|
+
if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:load_schema_current)
|
52
|
+
ActiveRecord::Tasks::DatabaseTasks.load_schema_current :sql, ENV['SCHEMA'], 'test'
|
53
|
+
else
|
54
|
+
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
|
55
|
+
end
|
38
56
|
end
|
39
57
|
end
|
40
58
|
|
41
|
-
|
59
|
+
desc "Recreate the test databases from the current schema"
|
42
60
|
task :load do
|
43
|
-
db_namespace["
|
61
|
+
db_namespace["parallel:purge"].invoke
|
44
62
|
case ActiveRecord::Base.schema_format
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
63
|
+
when :ruby
|
64
|
+
db_namespace["parallel:load_schema"].invoke
|
65
|
+
when :sql
|
66
|
+
db_namespace["parallel:load_structure"].invoke
|
49
67
|
end
|
50
68
|
end
|
51
69
|
|
52
|
-
|
70
|
+
desc "Check for pending migrations and load the test schema"
|
53
71
|
task :prepare => %w(environment load_config) do
|
54
72
|
unless ActiveRecord::Base.configurations.blank?
|
55
73
|
db_namespace['parallel:load'].invoke
|
@@ -57,3 +75,7 @@ db_namespace = namespace :db do
|
|
57
75
|
end
|
58
76
|
end
|
59
77
|
end
|
78
|
+
|
79
|
+
ParallelRSpec::RakeTask.new(:parallel_rspec) do |t|
|
80
|
+
t.pattern = "spec/**/*_spec.rb"
|
81
|
+
end
|
@@ -30,6 +30,11 @@ module ParallelRSpec
|
|
30
30
|
pid = fork do
|
31
31
|
channel_to_client.close
|
32
32
|
establish_test_database_connection(worker)
|
33
|
+
|
34
|
+
Config.after_fork.each do |proc|
|
35
|
+
proc.call(worker)
|
36
|
+
end
|
37
|
+
|
33
38
|
yield worker, channel_to_server
|
34
39
|
end
|
35
40
|
|
@@ -57,8 +62,16 @@ module ParallelRSpec
|
|
57
62
|
def establish_test_database_connection(worker)
|
58
63
|
ENV['TEST_ENV_NUMBER'] = worker.to_s
|
59
64
|
if defined?(ActiveRecord)
|
60
|
-
ActiveRecord::Base.configurations
|
61
|
-
|
65
|
+
if ActiveRecord::Base.configurations.respond_to?(:configs_for)
|
66
|
+
ActiveRecord::Base.configurations.configs_for(env_name: 'test').each do |configuration|
|
67
|
+
configuration.database << worker.to_s unless worker == 1
|
68
|
+
ActiveRecord::Base.establish_connection(configuration)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
configuration = ActiveRecord::Base.configurations['test']
|
72
|
+
configuration.with_indifferent_access['database'] << worker.to_s unless worker == 1
|
73
|
+
ActiveRecord::Base.establish_connection(configuration)
|
74
|
+
end
|
62
75
|
end
|
63
76
|
end
|
64
77
|
|
data/lib/parallel_rspec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "parallel_rspec/version"
|
2
|
+
require "parallel_rspec/config"
|
2
3
|
require "parallel_rspec/channel"
|
3
4
|
require "parallel_rspec/workers"
|
4
5
|
require "parallel_rspec/example"
|
@@ -7,3 +8,13 @@ require "parallel_rspec/client"
|
|
7
8
|
require "parallel_rspec/rake_task"
|
8
9
|
require "parallel_rspec/runner"
|
9
10
|
require "parallel_rspec/railtie"
|
11
|
+
|
12
|
+
module ParallelRSpec
|
13
|
+
def self.configure
|
14
|
+
yield Config
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.running?
|
18
|
+
Runner.running?
|
19
|
+
end
|
20
|
+
end
|
data/parallel_rspec.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.
|
23
|
-
spec.
|
22
|
+
spec.add_dependency "rake", "> 10.0"
|
23
|
+
spec.add_dependency "rspec"
|
24
24
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant, Powershop New Zealand Ltd
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '10.0'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '10.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
description: This gem lets you run your RSpec examples in parallel across across your
|
42
42
|
CPUs. Each worker automatically gets its own database to avoid conflicts. The
|
43
43
|
optional spring-prspec gem adds support for running under Spring.
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/parallel_rspec.rb
|
59
59
|
- lib/parallel_rspec/channel.rb
|
60
60
|
- lib/parallel_rspec/client.rb
|
61
|
+
- lib/parallel_rspec/config.rb
|
61
62
|
- lib/parallel_rspec/example.rb
|
62
63
|
- lib/parallel_rspec/railtie.rb
|
63
64
|
- lib/parallel_rspec/rake_task.rb
|
@@ -71,7 +72,7 @@ homepage: https://github.com/willbryant/parallel_rspec
|
|
71
72
|
licenses:
|
72
73
|
- MIT
|
73
74
|
metadata: {}
|
74
|
-
post_install_message:
|
75
|
+
post_install_message:
|
75
76
|
rdoc_options: []
|
76
77
|
require_paths:
|
77
78
|
- lib
|
@@ -86,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
|
-
|
90
|
-
|
91
|
-
signing_key:
|
90
|
+
rubygems_version: 3.0.3
|
91
|
+
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: This gem lets you run your RSpec examples in parallel across across your
|
94
94
|
CPUs.
|