Inspired by https://meta.discourse.org/t/setting-up-plugin-continuous-integration-tests-on-travis-ci/59612
This repo holds the scripts we use across our Discourse plugins to run tests in Travis CI and check coverage on Coveralls.
Incorporating these scripts into a plugin is a multi-step process:
Enable Travis CI for the repo of the plugin in question.
.travis.yml is a travis config file which runs these scripts, it should be placed in the root of a plugin repo.
A Travis cron job should be set up to run every day to test the plugin against the latest upstream code.
Enable Coveralls for the repo of the plugin in question.
This code must be run at the very top of every spec:
if ENV["COVERALLS"] || ENV["SIMPLECOV"] require "simplecov" if ENV["COVERALLS"] require "coveralls" SimpleCov.formatter = Coveralls::SimpleCov::Formatter end SimpleCov.start do root File.expand_path("../..", __FILE__) add_filter "spec/" add_filter "db/migrate" add_filter "gems/" end end require "rails_helper"For inconvenience plugin_helper.rb contains this code, and if placed in the plugin's spec/ folder, it can be included in specs with:
require_relative "plugin_helper"(which must also go at the very top of every spec)
This won't test coverage of code in a plugin's plugin.rb file, so all testable code should be moved into a separate file which can be included with require_relative.
When run locally it'll also place output in the coverage/ folder, so this should be added to the repo's .gitignore.
- Enable Travis CI
- Include
.travis.yml - Set up Travis cron job
- Enable Coveralls
- Include
plugin_helper.rb - Move testable code out of
plugin.rb - Add
coverageto.gitignore - Add build status and coverage status badges to
README.md
Bug reports should be filed by following the process described here.
.travis.yml and plugin_helper.rb also licensed under MPL-2.0