forked from rtomayko/tilt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ruby's coverage library does not support code loaded eval (and similar methods like {class,module,instance}_{eval,exec}). However, it would be nice to be able to get code coverage for your web application views. One simple way to do this is to write a file with the compiled template code, and then load it This adds Tilt::Template#compiled_path=, for setting a path for the template. There may be multiple compiled files based on this path if the template is render with multiple scope classes and/or local variables. load is used instead of require to prevent breaking things when the same path would be reused. The methods are unbound after the file is loaded, so using load instead of require makes sense for that. We do not want to delete the file after loading, since the main reason to use this feature is for coverage testing. Trying this in a real application showed indentation warnings in verbose warning mode. Fix those by not indenting the compiled template method preamble. In my testing, the coverage library didn't pickup relative loads by default, so this uses File.expand_path to expand the paths passed on Tilt::Template#compiled_path=. That's not required, but it seems useful enough to make it the default behavior.
- Loading branch information
1 parent
d8a3999
commit 384553f
Showing
2 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters