6

It looks like it's quite possible to get a useful coverage report for Haml code, due to its one one-statement-per-line structure.

Do you know of any code coverage tools for Haml? Maybe something is in the works?

Leonid Shevtsov
  • 14,024
  • 9
  • 51
  • 82
  • mmmm... I'm not quite sure how you would evaluate that one... – sevenseacat Mar 02 '11 at 11:04
  • 1
    I'm not a HAML fan, and questions like this confirm it. Do you need code coverage for HTML? What code are you testing? – Mark Thomas Mar 02 '11 at 12:40
  • 1
    You should have code coverage for any kind of web page generator, whether it looks like HTML with embedded computations (ASP, PHP, JSP, ...) or whether is simply procedural code that produces web page text. Otherwise you don't have a good way of knowing if your application is tested, because part of the application code is in these web-page generators. – Ira Baxter Mar 02 '11 at 22:22
  • 1
    I find it highly frustrating that people even ask things like do you need code coverage for HTML. It's dynamically generated and critical to the app. Of course it needs testing. – Abe Petrillo Feb 01 '13 at 16:25

2 Answers2

3

Code coverage generally makes sure you cover all your code-paths. If you have a lot of logic in your view, that is a smell. I think logic should be moved to your helpers, controllers (render a different view) or presenters, and those you can test with perfect coverage.

Aside of that: theoretically it should be possible, but i would not want to encourage placing too much "intelligence" in views.

nathanvda
  • 49,707
  • 13
  • 117
  • 139
  • 1
    OK, but what about branching? Surely you accept that there can be and are conditions in views. How would you know that your acceptance tests cover all code paths in views? – Leonid Shevtsov Mar 03 '11 at 10:47
  • For instance, what we do is rendering buttons or links depending on the rights of a user. We wrap the stuff to be rendered in a helper function that will evaluate the conditions and only allow the render if the user has the correct rights. No branching, code-path is simple, and you can test the helper perfectly. And of course simple checks could be in the view, but proposing code coverage for your view is imho encouraging the wrong code style. – nathanvda Mar 03 '11 at 11:16
1

One problem with non-mainstream languages (such as HAML) is that tools are hard to find, because they are hard to build.

This technical paper Branch Coverage for Arbitrary Languages Made Easy (I'm the author) describes how to build test coverage tools for langauges in systematic way to help get around this problem, using a generic tool-building infrastructure.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341