Module: Roda::RodaPlugins::RenderCoverage
- Defined in:
- lib/roda/plugins/render_coverage.rb
Overview
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.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.configure(app, opts = OPTS) ⇒ Object
Use the :dir option to set the directory to store the compiled template files, and the :strip_paths directory for paths to strip.
- .load_dependencies(app, opts = OPTS) ⇒ Object
Class Method Details
.configure(app, opts = OPTS) ⇒ Object
Use the :dir option to set the directory to store the compiled template files, and the :strip_paths directory for paths to strip.
43 44 45 46 47 |
# File 'lib/roda/plugins/render_coverage.rb', line 43 def self.configure(app, opts=OPTS) app.opts[:render_coverage_strip_paths] = opts[:strip_paths].map{|f| File.(f)} if opts.has_key?(:strip_paths) coverage_dir = app.opts[:render_coverage_dir] = opts[:dir] || app.opts[:render_coverage_dir] || 'coverage/views' Dir.mkdir(coverage_dir) unless File.directory?(coverage_dir) end |
.load_dependencies(app, opts = OPTS) ⇒ Object
36 37 38 |
# File 'lib/roda/plugins/render_coverage.rb', line 36 def self.load_dependencies(app, opts=OPTS) app.plugin :render end |