Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get coverage for views in Rails

Context

As asked before by others in 2012, see links below, I like to know if my Rails views are covered in my specs/cucs. I know that in 2012 the answer was that there was no solution. I was wondering if there is a solution now in 2014? I searched the web and did not find much, so I fear the answer is the same.

Motivation

I want to know if my cucumber features cover all parts of the API (in this case the GUI). When I add GUI functionality (new view, button, etc) but I somehow forget to add a cuccie for it, I want to get a notification. So it's not so much that I want to cover everything in my views, but I want to prevent that I unintentionally forget to add a cuccie for new user features. Hence reducing the chances of code not working in production.

Research

I found the following links, mentioned above:

  • How to test code coverage for Rails ERB templates?
  • How do I get coverage for view specs with rspec, rails, and simplecov?

A potentially interesting approach that I want to look into is:

  • Rack middleware to help measure production code coverage
like image 862
Axe Avatar asked Jan 30 '14 08:01

Axe


1 Answers

I want to prevent that I unintentionally forget to add a cuccie for new user features.

The pedantic answer is that you could make sure to write those tests before adding the features (or at least commit them at the same time.) But, that's overly dogmatic and not always realistic.

SimpleCov or another test coverage tool can help you monitor this indirectly, even though it can't measure coverage in views directly (because they're not written in Ruby.)

If you're covering every controller action, model and view helper method, then you're probably in good shape. (This works best if you avoid putting logic in the views wherever possible.)

like image 139
gphil Avatar answered Nov 12 '22 01:11

gphil