How to collect rcov style information in erb template processing?

I use rcov for a set of tests that are auto-generated from rails routes to collect information about dead code (code that is never called in the application). This setup already generates enlightening results for controllers, models, helpers, and lib code. Unfortunately, rcov does not track code coverage in erb templates, which makes sense, since erb templates are a rather complicated continuation of the normal execution concept.

The rails themselves can generate good reports about where in the template exceptions are raised and the like, so I feel that this is the data that can be collected.

I am currently trying to find points in rcov that I can connect to, but the nature of the Ouroboros system makes it difficult to see what happens clearly. I also suspect that some amount of ERB clearance will be required.

If you have ideas for approaches or solutions, I would appreciate it. Once I get the view customization, I clear this code and release it as an open-source Rails plugin.

+4
source share
1 answer

I really absolutely need view file names, since in most cases they will be fully executed. My goal is mainly to identify unused partial or patterns. The following code displays them.

module DeadCodeDetector module Template def set_extension_and_file_name_with_recording(use_full_path) r = set_extension_and_file_name_without_recording(use_full_path) puts "Included Template" puts filename puts "End Include" puts r end def self.included(base) base.class_eval do alias_method_chain :set_extension_and_file_name, :recording end end end end ActionView::Template.send(:include, DeadCodeDetector::Template) 
+1
source

Source: https://habr.com/ru/post/1286695/


All Articles