0vtrla
Last Updated: February 25, 2016
·
2.906K
· calamari
6b4b7f11163b1e87571995ce8c3f0bce

Make jasmine:ci use phantomjs (under Rails)

If you write jasmine specs within your rails app you probably know, that rake jasmine will start a webrick server serving your jasmine test suite under localhost:8888. You also probably know that you also can run your test suite using a selenium driver with the rake jasmine:ci command. This will start a server, spawn of a firefox instance that navigates to the test suite and after it has run, it will tell in your console if it failed or succeeded.

Making it headless

But running firefox is slow. You really want to use a headless browser for testing it. It's also good for jenkins (or any other continuous integration system). So, why not use PhantomJS?

You do not know how?

Well, I didn't really do either, until yesterday when a colleague finally looked into the jasmine-gem code. It's simple (but undocumented), so here it goes:

Install PhantomJS and then add a file called spec/javascripts/support/jasmine_helper.rb into your rails app with the following contents:

Jasmine.configure do |config|
  config.browser = :phantomjs
end

Thats it. Just runrake jasmine:ci` and see for yourself.

Say Thanks
Respond

1 Response
Add your response

9084
A6d3d51e4d6cb9fc361be1a7d6d1ce14

Doing this on Ubuntu 12.04, hit a problem with Jasmine server not being found. Turned out I had an OLD version of PhantomJS (1.4) via apt package manager - so do make sure you get a later version from the site (1.9.1, currently).

Great tip - just what I was after

over 1 year ago ·