I’d like to keep tackling rspec tests until we can reach at least 80% coverage on each of our respective plugins. On the coverage % front, Discourse has a useful gem called “simplecov” which will calculate the percentage of your code that is covered by tests based on what lines are touched in the course of a test suite. I’ve found that you can restrict SimpleCov to a plugin by adding the following to your spec/plugin_helper.rb file:
SimpleCov.configure do
add_filter do |src|
src.filename !~ /discourse-custom-wizard/ ||
src.filename =~ /spec/
end
end
Once this is added you run your plugin test suite like this to get a coverage report for your plugin:
You may find that data persists between tests, particularly data in the PluginStore. To ensure this doesn’t happen you can add this to your plugin_helper.rb file
RSpec.configure do |config|
config.around(:each) do |example|
ActiveRecord::Base.transaction do
example.run
raise ActiveRecord::Rollback
end
end
end
The issue seems to be that simplecov isn’t detecting your tests (i.e. 0 Lines)
Perhaps you’ve added a filter in your plugin_helper.rb that’s filtering out all the plugin paths?
add_filter do |src|
src.filename !~ /discourse-custom-wizard/ ||
src.filename =~ /spec/ ||
src.filename =~ /db/ ||
src.filename =~ /api/ ## API features are currently experimental
end
means filter out any file that includes BOTH discourse-follow and spec in its path. So it’s a bit broad, as nothing really will be filtered, apart from the follow specs. It will include files outside of the plugin. If you then look at the coverage report itself (it will appear as an index.html in a “coverage” folder in the root discourse foloder), we can see the actual files it’s covering
Your previous version
add_filter do |src|
src.filename !~ /discourse-follow/ ||
src.filename =~ /spec/
end
Actually works for me (I pulled your tests branch)
I’m getting a 64% figure.
Now if we look at the coverage report index.html it’s only covering the plugin files
Just for posterity, Rob and I had a 1.5hr call to try and debug this, but still no joy. If anyone has any experience with a similar simplecov issue, any tips would be most appreciated.
@merefield As we discussed, let’s move on for now, but it might be worth posting on meta too.