parallel_rspec 1.2.0 → 2.0.0

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: 19b61a06eaf02d7e86e49dbb7287884f351d3649accaa3d43fd7b59b11a70630
4
- data.tar.gz: 54902af922e58c98d47ae265c1d471a4ac819ac2aac8f31925cf4154c7630317
3
+ metadata.gz: 83c17d292ba1b11cd79f83f1d8b795d0e7a606fe605ab998fb8e71d6876212fe
4
+ data.tar.gz: e6504610a0782653c34ac985fa355588f3fe75880c41cfda63c637b5520c155f
5
5
  SHA512:
6
- metadata.gz: 6a54b4e9e0e0d8628bfb7fd33ad08a6f500dd7e1dd003bea96379dcfff623790b3ac3cb1f3fd76a53b127cbe62a75e5db4c8f3185994b23389e912da07e225f7
7
- data.tar.gz: fe3e3185122faa62befdb5d233cb82d51d4740ecb84ad0aaff3538bb5075c2d525927cc125e5fc56fee9546105996d3ad4e3f014b587618cc01a0188a4bbd144
6
+ metadata.gz: 50a9c698147a7d65ff0452d3c83898dc46a54173683b9fa0886fc9b50aea9daae6205664063ccaee63a936cab567e2e26a3a6ff7fdf2dbcd2e2304c06da4e697
7
+ data.tar.gz: a16b420371af5586f1ff8f86d398cf46344c6b292430e853c82ac349f53f28d42882eff736f416168a4fdaabf6ffe62d971bdca61410ff81ae2b363a7bc04081
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.3.
27
+ This version of ParallelRSpec has been tested with RSpec 3.10.
28
28
 
29
29
  ## Usage
30
30
 
@@ -66,6 +66,22 @@ To set up a rake task which uses parallel_rspec, use, for example:
66
66
  end
67
67
  ```
68
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
+
69
85
  ## Contributing
70
86
 
71
87
  Bug reports and pull requests are welcome on GitHub at https://github.com/willbryant/parallel_rspec.
@@ -74,6 +90,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/willbr
74
90
  ## Thanks
75
91
 
76
92
  * Charles Horn (@hornc)
93
+ * Roger Nesbitt (@mogest)
77
94
 
78
95
 
79
96
  ## License
@@ -44,6 +44,7 @@ module ParallelRSpec
44
44
  example.description,
45
45
  example.exception,
46
46
  example.location_rerun_argument,
47
+ ExampleGroup.new([]),
47
48
  example.metadata.slice(
48
49
  :absolute_file_path,
49
50
  :described_class,
@@ -0,0 +1,13 @@
1
+ module ParallelRSpec
2
+ module Config
3
+ @after_fork = []
4
+
5
+ def self.after_fork(&block)
6
+ if block
7
+ @after_fork << block
8
+ else
9
+ @after_fork
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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
@@ -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)
@@ -22,7 +22,11 @@ db_namespace = namespace :db do
22
22
  begin
23
23
  ParallelRSpec::Workers.new.run_test_workers do |worker|
24
24
  ActiveRecord::Schema.verbose = false
25
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
25
+ if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:load_schema_current)
26
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_current :ruby, ENV['SCHEMA'], 'test'
27
+ else
28
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
29
+ end
26
30
  end
27
31
  ensure
28
32
  if should_reconnect
@@ -34,7 +38,11 @@ db_namespace = namespace :db do
34
38
  # desc "Recreate the test database from an existent structure.sql file"
35
39
  task :load_structure => %w(db:parallel:purge) do
36
40
  ParallelRSpec::Workers.new.run_test_workers do |worker|
37
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
41
+ if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:load_schema_current)
42
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_current :sql, ENV['SCHEMA'], 'test'
43
+ else
44
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
45
+ end
38
46
  end
39
47
  end
40
48
 
@@ -1,3 +1,3 @@
1
1
  module ParallelRSpec
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  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['test']['database'] << worker.to_s unless worker == 1
61
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
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
 
@@ -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
@@ -19,7 +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.add_dependency "rake", "~> 10.0"
22
+ spec.add_dependency "rake", "> 10.0"
23
23
  spec.add_dependency "rspec"
24
- spec.add_development_dependency "bundler", "~> 1.10"
25
24
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
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: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2021-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '10.0'
20
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
26
  version: '10.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.10'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.10'
55
41
  description: This gem lets you run your RSpec examples in parallel across across your
56
42
  CPUs. Each worker automatically gets its own database to avoid conflicts. The
57
43
  optional spring-prspec gem adds support for running under Spring.
@@ -72,6 +58,7 @@ files:
72
58
  - lib/parallel_rspec.rb
73
59
  - lib/parallel_rspec/channel.rb
74
60
  - lib/parallel_rspec/client.rb
61
+ - lib/parallel_rspec/config.rb
75
62
  - lib/parallel_rspec/example.rb
76
63
  - lib/parallel_rspec/railtie.rb
77
64
  - lib/parallel_rspec/rake_task.rb
@@ -85,7 +72,7 @@ homepage: https://github.com/willbryant/parallel_rspec
85
72
  licenses:
86
73
  - MIT
87
74
  metadata: {}
88
- post_install_message:
75
+ post_install_message:
89
76
  rdoc_options: []
90
77
  require_paths:
91
78
  - lib
@@ -100,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
87
  - !ruby/object:Gem::Version
101
88
  version: '0'
102
89
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.7.6
105
- signing_key:
90
+ rubygems_version: 3.0.3
91
+ signing_key:
106
92
  specification_version: 4
107
93
  summary: This gem lets you run your RSpec examples in parallel across across your
108
94
  CPUs.