General Setup for Ruby on Rails
You will require:
- Ruby on Rails 6.0 and above
- Ruby v2.7 and above
- SimpleCov up & running
- Setup guide: readme in their repo
- If your setup is correct, you should see
coverage/.resultset.json
file in your project directory after every test run.
Install & Configure
Add this into the Gemfile
and run bundle
:
gem "oyencov"
group :test do
gem "simplecov"
end
Set these environment variables in both your CI and production environment:
OYENCOV_API_KEY= # Given in the portal
Leave this env var unset in local environments. OyenCov will only start tracking and submit data if these variables are present.
For Puma, if started with "bin/rails server"
Add this at the end in config/puma.rb
to support cluster mode:
plugin :oyencov
For Puma, if started with command "puma"
Add this in config/puma.rb
:
require "oyencov"
require "oyencov/puma/plugin/oyencov"
# Add these at the very beginning of the file
# Add this at the end of the file
plugin :oyencov
Please make sure the OYENCOV_API_KEY exists as environment variable before the puma
command is run. If you are using other ways to configure secrets, please let us know, we will work on supporting it.
The main reason for these extra steps is because OyenCov is meant to be loaded after Rails, not before. By running puma
first, the load sequence becomes a bit like puma -> bundler (.., oyencov) -> rails
.