Skip to content

Commit

Permalink
Fixed parallel tests in Rails v6.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Feb 1, 2020
1 parent c6a524e commit cd73b53
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.0.2

* Fixed parallel tests in Rails v6.

## 6.0.1

* Changed gemspec to `railties` vs `rails`. Thanks @seuros
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_v5.1.x.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
minitest-spec-rails (6.0.1)
minitest-spec-rails (6.0.2)
minitest (>= 5.0)
railties (>= 4.1)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_v5.2.x.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
minitest-spec-rails (6.0.1)
minitest-spec-rails (6.0.2)
minitest (>= 5.0)
railties (>= 4.1)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_v6.0.x.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
minitest-spec-rails (6.0.1)
minitest-spec-rails (6.0.2)
minitest (>= 5.0)
railties (>= 4.1)

Expand Down
30 changes: 30 additions & 0 deletions lib/minitest-spec-rails/parallelize.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# HACK: stolen and altered from https://github.com/blowmage/minitest-rails/pull/218/files
# Which was referenced in https://github.com/metaskills/minitest-spec-rails/issues/94

module MiniTestSpecRails
##
# This module is a placeholder for all the Test classes created using the
# spec DSL. Normally all classes are created but not assigned to a constant.
# This module is where constants will be created for these classes.
module SpecTests #:nodoc:
end
end

module Kernel #:nodoc:
alias describe_before_minitest_spec_constant_fix describe
private :describe_before_minitest_spec_constant_fix
def describe *args, &block
cls = describe_before_minitest_spec_constant_fix(*args, &block)
cls_const = "Test__#{cls.name.to_s.split(/\W/).reject(&:empty?).join('_'.freeze)}"
if block.source_location
source_path, line_num = block.source_location
source_path = Pathname.new(source_path).relative_path_from(Rails.root).to_s
source_path = source_path.split(/\W/).reject(&:empty?).join("_".freeze)
cls_const += "__#{source_path}__#{line_num}"
end
cls_const += "_1" while MiniTestSpecRails::SpecTests.const_defined? cls_const
MiniTestSpecRails::SpecTests.const_set cls_const, cls
cls
end
end
1 change: 1 addition & 0 deletions lib/minitest-spec-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Railtie < ::Rails::Railtie
config.before_initialize do |_app|
require 'active_support'
require 'minitest-spec-rails/init/active_support'
require 'minitest-spec-rails/parallelize'
ActiveSupport.on_load(:action_controller) do
require 'minitest-spec-rails/init/action_controller'
require 'minitest-spec-rails/init/action_dispatch'
Expand Down
2 changes: 1 addition & 1 deletion lib/minitest-spec-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MiniTestSpecRails
VERSION = '6.0.1'.freeze
VERSION = '6.0.2'.freeze
end

0 comments on commit cd73b53

Please sign in to comment.