Phantomjs as a Rubygem
DISCLAIMER: Alpha status, YMMV!
It keeps installations of phantomjs in
$HOME/.phantomjs/VERSION/PLATFORM. When you call
will return the path to the phantomjs executable in there. If that is not present, it will first fetch and
install the prebuilt packages suitable for the current plattform (currently Linux 32/64 or OS X supported).
You will need
wget on your system. For extraction,
tar are required on Linux, and
on OS X. They should be installed already.
TL;DR: Instead of manually installing phantomjs on your machines, use this gem. It will take care of it.
require 'phantomjs' Phantomjs.path # => path to a phantom js executable suitable to your current platform. Will install before return when not installed yet.
Usage with Poltergeist/Capybara
Add this to your
group :test do gem 'phantomjs', :require => 'phantomjs/poltergeist' end
This will automatically require (and install) phantomjs and configure Capybara in the same way as noted below for manual setup
gem 'phantomjs', :group => :test to your
Gemfile and run
bundle. In your test/spec helper, re-configure
the Poltergeist capybara driver to use the phantomjs package from this gem:
require 'phantomjs' # <-- Not required if your app does Bundler.require automatically (e.g. when using Rails) Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path) end
Check out the poltergeist docs for all the options you can pass in there.
A note about versions.
The gem version consists of 4 digits: The first 3 indicate the phantomjs release installed via this gem, the last one is the internal version of this gem, in case I screw things up and need to push another release before
Phantomjs.implode when it is loaded, which purges the
directory. This is no bad thing, it just means every time you run the specs you'll download and install all
three packages over, so tread with caution please :)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
(c) 2012 Christoph Olszowka
Note that this project merely simplifies the installation of the entirely separate PhantomJS project via a Ruby gem. You can find the license information for PhantomJS at http://http://phantomjs.org/