• Stars
    star
    222
  • Rank 179,123 (Top 4 %)
  • Language
    Ruby
  • License
    Other
  • Created over 12 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Phantomjs via Rubygems: Auto-install phantomjs on demand for current platform. Comes with poltergeist integration.

PhantomJS as a RubyGem

Build Status

DISCLAIMER: Alpha status, YMMV!

I am lazy as hell, and wanted to be able to install PhantomJS via Rubygems/Bundler when using poltergeist.

It keeps installations of phantomjs in $HOME/.phantomjs/VERSION/PLATFORM. When you call Phantomjs.path, it 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).

If there is a phantomjs executable in your $PATH that matches the version number packaged in this gem, this one will be used instead of installing one in your $HOME/.phantomjs.

You will need cURL or wget on your system. For extraction, bunzip2 and tar are required on Linux, and unzip 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.

Example

require 'phantomjs'
Phantomjs.path # => path to a phantom js executable suitable to your current platform. Will install before return when not installed yet.

# Or run phantomjs with the passed arguments:
Phantomjs.run('./path/to/script.js') # => returns stdout

# Also takes a block to receive each line of output:
Phantomjs.run('./path/to/script.js') { |line| puts line }

Usage with Poltergeist/Capybara

Add this to your Gemfile:

group :test do
    gem 'poltergeist'
    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.

Note that you need to add poltergeist as a dependency explicitly since it is not a dependency of this gem in order to avoid forcing users to install poltergeist if the just want to use phantomjs itself.

Manual setup

Add 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 in the interim.

Contributing

Warning: The spec_helper calls Phantomjs.implode when it is loaded, which purges the ~/.phantomjs 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. :)

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

(c) 2013-2014 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://phantomjs.org/

More Repositories

1

serious

Serious is a simple, file-driven blog engine inspired by toto and driven by sinatra with an emphasis on easy setup
Ruby
76
star
2

rvm-completion

bash completion for Ruby Version Manager including installed rubies and gemsets for current ruby
Ruby
36
star
3

transactionata

Transactionata: Transactional dynamic test data for Rails Tests. Set up your models and factories in a block that will be executed once and then rolled back by hooking into ActiveRecord's built-in fixture transactions
Ruby
35
star
4

xbmc-client

A simple Ruby client for the XBMC Media Center JSON-RPC API
Ruby
31
star
5

activerecord-skeleton

A basic skeleton for ActiveRecord-backed Ruby apps
Ruby
26
star
6

linux-typewriter

For when you want to make sounds when typing...
Python
25
star
7

gedit-snippets

Ruby, Rails and RHTML snippets for the gedit Snippets plugin
Ruby
23
star
8

rack-fontserve

Sinatra app for serving web fonts easily with proper caching and access-control headers
Ruby
15
star
9

redirect_follower

Allows you to resolve redirecting urls (i.e. from url-shortening services like bit.ly) with Net::HTTP and find out their destination url as well as the body
Ruby
14
star
10

rack-boilerplate

A lean boilerplate for developing ruby/rack web applications with sane defaults out of the box
Ruby
9
star
11

stupid_formatter

A stupid formatter for piping text through markup processors
Ruby
9
star
12

github_metadata

Extracts additional information from Github repos that isn't available via API
Ruby
4
star
13

thin_balance

Run multiple thin instances of your rack app load-balanced using pen in development so concurrent requests are possible.
Ruby
4
star
14

redmine_commit_issue_links

Redmine plugin that links up "#1234" from your commit messages against the issue with that id
2
star
15

docker-toolkit

Alpine-based docker image that contains useful command line utilities like curl, jq, netcat, socat, ruby, and more
Shell
2
star
16

html_page_title

Retrieve the page title for a given url using redirect_follower and hpricot
Ruby
1
star
17

first_github_commit

Find the first commit for a given github repository and return the API info about it
Ruby
1
star
18

hashie-lazy_trash

An extended version of Hashie::Trash (for hashie v2+)
Ruby
1
star
19

rack_demo

Just a very simple Rack demo application for testing purposes that uses foreman and unicorn
Ruby
1
star
20

grumpy_herring

Generates names for your startup's pricing plans
Ruby
1
star
21

study

Easy application operation metrics with Ruby using munin and redis
Ruby
1
star
22

looprun

looprun is a simple script to repeatedly execute shell commands after they exit - for example to automatically restart your server
Ruby
1
star
23

coverage-bug

Demonstration of bug in Ruby coverage
Ruby
1
star