module Roda::RodaPlugins::RenderCoverage

  1. lib/roda/plugins/render_coverage.rb

The render_coverage plugin builds on top of the render plugin and sets compiled_path on created templates. This allows Ruby’s coverage library before Ruby 3.2 to consider code created by templates. You may not need this plugin on Ruby 3.2+, since on Ruby 3.2+, coverage can consider code loaded with eval. This plugin is only supported when using tilt 2.1+, since it requires the compiled_path supported added in tilt 2.1.

By default, the render_coverage plugin will use coverage/views as the directory containing the compiled template files. You can change this by passing the :dir option when loading the plugin. By default, the plugin will set the compiled_path by taking the template file path, stripping off any of the allowed_paths used by the render plugin, and converting slashes to dashes. You can override the allowed_paths to strip by passing the :strip_paths option when loading the plugin. Paths outside :strip_paths (or the render plugin allowed_paths if :strip_paths is not set) will not have a compiled_path set.

Due to how Ruby’s coverage library works in regards to loading a compiled template file with identical code more than once, it may be beneficial to run coverage testing with the RODA_RENDER_COMPILED_METHOD_SUPPORT environment variable set to no if using this plugin.

Methods

Public Class

  1. configure
  2. load_dependencies

Public Class methods

configure(app, opts=OPTS)

Use the :dir option to set the directory to store the compiled template files, and the :strip_paths directory for paths to strip.

[show source]
   # File lib/roda/plugins/render_coverage.rb
43 def self.configure(app, opts=OPTS)
44   app.opts[:render_coverage_strip_paths] = opts[:strip_paths].map{|f| File.expand_path(f)} if opts.has_key?(:strip_paths)
45   coverage_dir = app.opts[:render_coverage_dir] = opts[:dir] || app.opts[:render_coverage_dir] || 'coverage/views'
46   Dir.mkdir(coverage_dir) unless File.directory?(coverage_dir)
47 end
load_dependencies(app, opts=OPTS)
[show source]
   # File lib/roda/plugins/render_coverage.rb
36 def self.load_dependencies(app, opts=OPTS)
37   app.plugin :render
38 end