public
Last active

This is a bare-minimum testem configuration file that will allow you to use testem with a rails project. You save it in the root directory of the project (at the same level as the Gemfile), and then you can navigate to the project and run testem. How it works: What this configuration does is precompile the assets before the tests are run using the asset pipeline. After the tests are run, the precompiled assets are removed. I use RSPEC, so I put my tests in spec/scripts/ to follow the existing directory structure. Keep in mind that sometimes browsers may fail their tests because the files are removed. The way to resolve this is to simply re-run the tests. And the tests may be slow to run because of the precompilation process, but it's not terrible. Plus, it makes sure you are testing your code as it will appear in production (which is what you want!).

  • Download Gist
testem.json
JSON
1 2 3 4 5 6 7 8 9 10 11 12 13
{
"framework": "jasmine",
"src_files": [
"app/assets/javascripts/*.js",
"spec/scripts/*.js"
],
"serve_files": [
"public/assets/*.js",
"spec/scripts/*.js"
],
"before_tests": "rake assets:precompile RAILS_ENV=development",
"after_tests": "rm -rf public/assets/"
}

If precompiling your assets takes too much time you may use symbolic links: http://afurmanov.com/2013/08/20/testing-javascript-in-isolation-from-rails/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.