Skip to content

Commit de763e4

Browse files
authored
Merge pull request #522 from wri/chore/parallel-specs
Add parallel tests gem
2 parents fe8ab0b + faf1813 commit de763e4

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
env:
5353
POSTGRES_USER: ${{ env.POSTGRES_USER }}
5454
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
55+
RAILS_ENV: test
5556
ports: ["5432:5432"]
5657
steps:
5758
- uses: actions/checkout@v4
@@ -68,10 +69,10 @@ jobs:
6869
bundler-cache: true
6970

7071
- name: Setup test database
71-
run: bin/rails db:create db:schema:load
72+
run: bin/rake parallel:setup
7273

7374
- name: Run tests
74-
run: bundle exec rspec spec
75+
run: bin/rake parallel:spec
7576

7677
- name: Upload Code Coverage
7778
uses: actions/upload-artifact@v4

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ group :development, :test do
112112
gem "debug", platforms: %i[mri mingw x64_mingw]
113113
gem "factory_bot_rails"
114114
gem "faker"
115+
gem "parallel_tests"
115116
gem "rails-erd"
116117
gem "rubocop-rails"
117118
gem "standard"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ GEM
507507
activerecord (>= 6.1)
508508
request_store (~> 1.4)
509509
parallel (1.26.3)
510+
parallel_tests (4.9.1)
511+
parallel
510512
paranoia (3.0.1)
511513
activerecord (>= 6, < 8.1)
512514
parser (3.3.7.1)
@@ -847,6 +849,7 @@ DEPENDENCIES
847849
oj
848850
oj_mimic_json
849851
paper_trail
852+
parallel_tests
850853
paranoia
851854
pg
852855
puma

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ Run rspec:
150150
bundle exec rspec
151151
```
152152

153+
You can also run tests in parallel. To do that you need to create a test database for each parallel process:
154+
155+
```ruby
156+
bundle exec rake parallel:create
157+
bundle exec rake parallel:prepare
158+
```
159+
160+
And then run the tests:
161+
162+
```ruby
163+
bundle exec parallel:spec
164+
```
165+
166+
To drop all test databases:
167+
168+
```ruby
169+
bundle exec rake parallel:drop
170+
```
171+
172+
For more information about parallel tests check [parallel_tests gem.](https://github.com/grosser/parallel_tests)
173+
153174
## DOCUMENTATION ##
154175

155176
### API ###

config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ development:
1515

1616
test:
1717
<<: *default
18-
database: fti_test
18+
database: fti_test<%= ENV['TEST_ENV_NUMBER'] %>
1919

2020
e2e:
2121
<<: *default

db/seeds.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
unless Rails.env.development? || Rails.env.e2e?
2+
$stdout.puts "Seeding is only allowed in development or e2e environment"
3+
return
4+
end
15
# # sh "bin/rails db:fixtures:load FIXTURES_PATH=db/fixtures"
26
require "active_record/fixtures"
37

0 commit comments

Comments
 (0)