Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions ruby_on_rails/rspec.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Add the following gems to your Gemfile:
group :development, :test do
gem "factory_bot_rails"
gem "rspec-rails"
gem "parallel_tests"
end

group :test do
gem "rspec-core-parallel"
gem "shoulda-matchers"
gem "simplecov", require: false
gem "super_diff"
Expand All @@ -34,7 +34,14 @@ You should know exactly why you are adding each one of them and why is necessary

### spec/spec_helper.rb

Add SimpleCov configuration at the top of the file (before `RSpec.configure`):
Require [rspec-core-parallel](https://github.com/renuo/rspec-core-parallel) at the top of the file, so that `rspec` runs the suite
in parallel, with one worker per physical CPU core and a test database per worker:

```ruby
require "rspec/core/parallel"
```

Then add the SimpleCov configuration right after it (before `RSpec.configure`):

```ruby
# Run code coverage and exclude files with less than 5 lines of code
Expand Down Expand Up @@ -155,7 +162,16 @@ SELENIUM_DRIVER="selenium_chrome_headless"
config.generators { |g| g.test_framework :rspec }
```

* Add the line `bundle exec parallel_rspec` to `bin/check`
* Add the line `bundle exec rspec` to `bin/check`

### CI

* Create the test database with `bin/rails db:create db:schema:load`, as the Semaphore template does. The databases
of the workers (`test_0`, `test_1`, ...) are created by the gem, also when `DATABASE_URL` is set.
* The Semaphore template of [`renuo configure-semaphore`](./configure_ci.md) caches `tmp/rspec_parallel_run_times.txt`
between builds.

If the log of a CI run keeps saying `without run times of a previous run`, the file is not cached correctly.

> [!NOTE]
> If you want to debug a spec, you can simply uncomment the line `SELENIUM_DRIVER` in the .env to not run it headless.
Expand Down
Loading