SimpleCov with Selenium/Rails SimpleCov with Selenium/Rails selenium selenium

SimpleCov with Selenium/Rails


simplecov author here. Whenever you launch SimpleCov, it applies the coverage analysis to the currently running process. Therefore, you would need to launch SimpleCov inside your Rails server process. I would recommend adding the SimpleCov setup as a conditional to your Rails app's config/boot.rb (at the very top), like so:

# config/boot.rbif ENV["SELENIUM"]  require 'simplecov'  SimpleCov.start 'rails'end

Before booting your Rails test server, set that environment variable. You should now receive a coverage report once the test server is shut down. Please check out the config options if you want to move it to another directory so it does not interfere with your regular (unit/functional) coverage report.

I am not sure that boot.rb is the right place though. The fact is that SimpleCov needs to be loaded before anything else in your app is required or it won't be able to track coverage for those files. You might need to experiment or have a look into the rails boot process to find that place, but as the Bundler setup is part of boot.rb (if I remember correctly...), putting the mentioned config above the Bundler.setup should be fine.

Basically, with a similar setup you can even get code coverage for your local manual browser-based testing by launching simplecov in your server process, clicking around and exiting the server, if for example you want to know what part of your application a certain action really touches.