Here's one strategy I've been using that offers several benefits that were previously hard to combine:
- write both code and tests in any combination of pre-processable languages, relying on Sprockets and the asset pipeline to automatically find and compile everything.
- tests can execute in the browser with a nice graphical UI.
- the exact same tests can execute from the shell with no browser. I'm using therubyracer.
And I have an "app/assets/javascripts/test" directory that contains Jasmine specs. All the tests defined in there will automatically be included.
To run in the browser, you just need
<script type="text/javascript" src="/assets/test"></script>
. But for maximum debugability, put it into an Erb template and use <%= javascript_include_tag "test" %>
. That way you can call it with &debug_assets=1
to get useful filenames and line numbers in your stack traces.
To run from the shell, we can grab our source directly out of the asset pipeline and stick it into a Javascript execution environment:
Of course there are still a few more details to take care of to trigger the tests, produce nice console output, and set Rake's exit status. Here is a full example config.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.