-
Notifications
You must be signed in to change notification settings - Fork 231
SimpleCov
Daniel Leong edited this page Oct 26, 2017
·
7 revisions
Getting zeus to work with SimpleCov is a bit of a pain. If you really want it though, this page tells you one way to get them to play better together.
SimpleCov hinges upon two things that do not work well with zeus:
- SimpleCov needs to start and exit within the same process.
-
SimpleCov.start
needs to start before you load your application code (files are tracked once they are required).
NOTE: This page discusses a solution for rspec, but test unit should work about the same. Minitest solution
To satisfy both of these, we need to put the code that starts SimpleCov in a method that Zeus calls instead of within the spec helper file. Next, we need to manually require every file that you want to ensure is tracked.
Here are the steps and code to get this working:
- If you do not already have a zeus.json file and custom_plan.rb, run
zeus init
- Modify custom_plan.rb and spec_helper.rb as below
- Restart zeus
- Run your specs with zeus (
zeus rspec spec
) - $$$ profit
custom_plan.rb:
require 'zeus/rails'
class CustomPlan < Zeus::Rails
def test
require 'simplecov'
SimpleCov.start
# SimpleCov.start 'rails' if using RoR
# require all ruby files
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
# run the tests
super
end
end
Zeus.plan = CustomPlan.new
spec_helper.rb:
# this part is optional, but it gets SimpleCov working when running
# specs without zeus (as long as zeus is not running)
def zeus_running?
File.exists? '.zeus.sock'
end
if !zeus_running?
require 'simplecov'
SimpleCov.start
end
- https://github.com/colszowka/simplecov
- https://gist.github.com/ao140505/4982244
- https://github.com/colszowka/simplecov/issues/42
- http://www.ruby-doc.org/stdlib-1.9.3/libdoc/coverage/rdoc/Coverage.html
Overwrite simplecov at_exit method and do result.format! with after_run.
SimpleCov.at_exit {}
Minitest.after_run do
SimpleCov.result.format!
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end