Last Updated: February 25, 2016
·
2.022K
· EnriqueVidal

Headless javascript tests in rails

If you're using the asset-pipeline and you wish to test your coffeescript or javascript files using jasmine headless, do not fear evergreen is here:

In your Gemfile:

gem 'evergreen',  :group => [ :test, :development ], :require => 'evergreen/rails'

Then configure evergreen to use webkit in config/evergreen.rb:

require 'capybara-webkit'

Evergreen.configure do |config|
  config.driver       = :webkit
  config.public_dir   = 'public'
  config.spec_dir     = 'spec/javascripts'
  config.template_dir = 'spec/javascripts/templates'
end

To use the asset pipeline in your javascript specs (and use coffeescript instead of javascript in your specs just add your spec folder to the asset pipeline in development)

Do this in your config/environments/development.rb:

config.assets.paths << Rails.root.join('spec', 'javascripts').to_s

Finally you can now run rake spec:javascripts to run your javascript tests headlessly, if you wish you can run them in the browser too by visiting http://yourapp/evergreen (this route only works in development).

2 Responses
Add your response

Evergreen is a cool project, it's a pitty that's lacking a maintainer

over 1 year ago ·

the jasmine-rails project has a drop dead simple way to integrate a jasmine javascript test suite into your rails app:
https://github.com/searls/jasmine-rails

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip