From 382b6014f5e86636648901363f0d15db58c13bbd Mon Sep 17 00:00:00 2001 From: Michel Filipe Date: Mon, 28 Jul 2025 11:48:43 -0300 Subject: [PATCH 1/6] Prioritize PARALLEL_RAILS_ENV over RAILS_ENV --- lib/parallel_tests/tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parallel_tests/tasks.rb b/lib/parallel_tests/tasks.rb index 17f3044a..2a73b3b5 100644 --- a/lib/parallel_tests/tasks.rb +++ b/lib/parallel_tests/tasks.rb @@ -6,7 +6,7 @@ module ParallelTests module Tasks class << self def rails_env - 'test' + ENV['PARALLEL_RAILS_ENV'] || ENV['RAILS_ENV'] || 'test' end def load_lib From 456f7733f997229f1e93742eae0adbbf6497511b Mon Sep 17 00:00:00 2001 From: Michel Filipe Date: Mon, 28 Jul 2025 11:50:40 -0300 Subject: [PATCH 2/6] RSpec tests --- spec/parallel_tests/tasks_spec.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/parallel_tests/tasks_spec.rb b/spec/parallel_tests/tasks_spec.rb index ff2fa046..a09373ab 100644 --- a/spec/parallel_tests/tasks_spec.rb +++ b/spec/parallel_tests/tasks_spec.rb @@ -42,13 +42,19 @@ end describe ".rails_env" do - it "should be test" do + it "should be test when nothing was set" do expect(ParallelTests::Tasks.rails_env).to eq("test") end - it "should disregard whatever was set" do + it "should be whatever was set" do ENV["RAILS_ENV"] = "foo" - expect(ParallelTests::Tasks.rails_env).to eq("test") + expect(ParallelTests::Tasks.rails_env).to eq("foo") + end + + it "should prioritize the PARALLEL_RAILS_ENV value over the standard" do + ENV["RAILS_ENV"] = "foo" + ENV["PARALLEL_RAILS_ENV"] = "bar" + expect(ParallelTests::Tasks.rails_env).to eq("bar") end end From 00abe9f0e66371232b667f60b08be3cf0af8e0b9 Mon Sep 17 00:00:00 2001 From: Michel Filipe Date: Mon, 28 Jul 2025 11:51:16 -0300 Subject: [PATCH 3/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55925dab..5738eb1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,12 @@ only add here if you are working on a PR ### Breaking Changes +- `test` is not a hardcoded environment for rake tasks + ### Added +- Rake tasks will prioritize the `PARALLEL_RAILS_ENV` value over the standard `RAILS_ENV`, so setups where `RAILS_ENV` changes during the process will keep the `PARALLEL_RAILS_ENV` value + ### Fixed ## 5.3.1 - 2025-07-23 From 6624d1a8c4116a4ddb7eae05ecd0e6f57417de7e Mon Sep 17 00:00:00 2001 From: Michel Filipe Date: Mon, 28 Jul 2025 12:50:50 -0300 Subject: [PATCH 4/6] Add doc in Readme.md --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 0d529edc..dc3b72e0 100644 --- a/Readme.md +++ b/Readme.md @@ -360,6 +360,7 @@ TIPS - Debug errors that only happen with multiple files using `--verbose` and [cleanser](https://github.com/grosser/cleanser) - `export PARALLEL_TEST_PROCESSORS=13` to override default processor count - `export PARALLEL_TEST_MULTIPLY_PROCESSES=.5` to override default processor multiplier + - `export PARALLEL_RAILS_ENV=environment_name` to override default `RAILS_ENV` - Shell alias: `alias prspec='parallel_rspec -m 2 --'` - [Spring] Add the [spring-commands-parallel-tests](https://github.com/DocSpring/spring-commands-parallel-tests) gem to your `Gemfile` to get `parallel_tests` working with Spring. - `--first-is-1` will make the first environment be `1`, so you can test while running your full suite.
From 30b7ffff85303e68eec6a7b1c676b066abafef5b Mon Sep 17 00:00:00 2001 From: Michel Filipe Date: Mon, 28 Jul 2025 14:02:27 -0300 Subject: [PATCH 5/6] Add a reference to #776 in the changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5738eb1d..f5f5a6d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ only add here if you are working on a PR ### Added -- Rake tasks will prioritize the `PARALLEL_RAILS_ENV` value over the standard `RAILS_ENV`, so setups where `RAILS_ENV` changes during the process will keep the `PARALLEL_RAILS_ENV` value +- Rake tasks will prioritize the `PARALLEL_RAILS_ENV` value over the standard `RAILS_ENV`, so setups where `RAILS_ENV` changes during the process will keep the `PARALLEL_RAILS_ENV` value (see https://github.com/grosser/parallel_tests/pull/776) ### Fixed From c3b0bbf3cc0dbe3af0df64db98e061db890bfdf5 Mon Sep 17 00:00:00 2001 From: Michel Filipe Date: Sat, 2 Aug 2025 01:38:04 -0300 Subject: [PATCH 6/6] Adapt the code based on @grosser's suggestion https://github.com/grosser/parallel_tests/pull/1019#pullrequestreview-3064149293 --- CHANGELOG.md | 4 +--- Readme.md | 2 +- lib/parallel_tests/tasks.rb | 2 +- spec/parallel_tests/tasks_spec.rb | 6 ------ 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f5a6d6..45e84774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,9 @@ only add here if you are working on a PR ### Breaking Changes -- `test` is not a hardcoded environment for rake tasks - ### Added -- Rake tasks will prioritize the `PARALLEL_RAILS_ENV` value over the standard `RAILS_ENV`, so setups where `RAILS_ENV` changes during the process will keep the `PARALLEL_RAILS_ENV` value (see https://github.com/grosser/parallel_tests/pull/776) +- Rake tasks will prioritize the `PARALLEL_RAILS_ENV` value over the default `test` environment ### Fixed diff --git a/Readme.md b/Readme.md index dc3b72e0..e43f62b2 100644 --- a/Readme.md +++ b/Readme.md @@ -360,7 +360,7 @@ TIPS - Debug errors that only happen with multiple files using `--verbose` and [cleanser](https://github.com/grosser/cleanser) - `export PARALLEL_TEST_PROCESSORS=13` to override default processor count - `export PARALLEL_TEST_MULTIPLY_PROCESSES=.5` to override default processor multiplier - - `export PARALLEL_RAILS_ENV=environment_name` to override default `RAILS_ENV` + - `export PARALLEL_RAILS_ENV=environment_name` to override the default `test` environment - Shell alias: `alias prspec='parallel_rspec -m 2 --'` - [Spring] Add the [spring-commands-parallel-tests](https://github.com/DocSpring/spring-commands-parallel-tests) gem to your `Gemfile` to get `parallel_tests` working with Spring. - `--first-is-1` will make the first environment be `1`, so you can test while running your full suite.
diff --git a/lib/parallel_tests/tasks.rb b/lib/parallel_tests/tasks.rb index 2a73b3b5..63af70cc 100644 --- a/lib/parallel_tests/tasks.rb +++ b/lib/parallel_tests/tasks.rb @@ -6,7 +6,7 @@ module ParallelTests module Tasks class << self def rails_env - ENV['PARALLEL_RAILS_ENV'] || ENV['RAILS_ENV'] || 'test' + ENV['PARALLEL_RAILS_ENV'] || 'test' end def load_lib diff --git a/spec/parallel_tests/tasks_spec.rb b/spec/parallel_tests/tasks_spec.rb index a09373ab..a2dd3721 100644 --- a/spec/parallel_tests/tasks_spec.rb +++ b/spec/parallel_tests/tasks_spec.rb @@ -46,13 +46,7 @@ expect(ParallelTests::Tasks.rails_env).to eq("test") end - it "should be whatever was set" do - ENV["RAILS_ENV"] = "foo" - expect(ParallelTests::Tasks.rails_env).to eq("foo") - end - it "should prioritize the PARALLEL_RAILS_ENV value over the standard" do - ENV["RAILS_ENV"] = "foo" ENV["PARALLEL_RAILS_ENV"] = "bar" expect(ParallelTests::Tasks.rails_env).to eq("bar") end