phantomjs2 2.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.simplecov +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/LICENSE +27 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/lib/phantomjs/platform.rb +174 -0
- data/lib/phantomjs/poltergeist.rb +13 -0
- data/lib/phantomjs/version.rb +3 -0
- data/lib/phantomjs.rb +63 -0
- data/phantomjs.gemspec +24 -0
- data/spec/phantomjs_spec.rb +50 -0
- data/spec/platform_spec.rb +203 -0
- data/spec/runner.js +3 -0
- data/spec/spec_helper.rb +11 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 93ffbc2137a6851480df988eb0fc5f132de08696
|
4
|
+
data.tar.gz: 3be19fde14a1b706edd7d7ed1ca25e0d104fc0f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d3b11e86eb356dd0fc1f7d36062f262b789c8feabb8616dd6235ff68579faf7911cf03f61330d7a08023c5fdf295e24b6462627d73af24ade5e254da38a744a
|
7
|
+
data.tar.gz: 35d468a8ecbf34e0773b85bd590404b84bda72b24cdd539a1203c8d6ee5ca792a7e9e26d778755d0b2bd4ae639b851bff19d31f7fc78b1806b515410c89fb65b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
SimpleCov.start
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Note that this project merely bundles the separate PhantomJS project
|
2
|
+
into a Ruby gem. You can find the license information for PhantomJS
|
3
|
+
inside phantomjs/LICENSE.BSD and further information at
|
4
|
+
http://http://phantomjs.org/
|
5
|
+
|
6
|
+
Copyright (c) 2013 Christoph Olszowka
|
7
|
+
|
8
|
+
MIT License
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
a copy of this software and associated documentation files (the
|
12
|
+
"Software"), to deal in the Software without restriction, including
|
13
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be
|
19
|
+
included in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
22
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
24
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
25
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
26
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# PhantomJS as a RubyGem
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/colszowka/phantomjs-gem.png?branch=master)](https://travis-ci.org/colszowka/phantomjs-gem)
|
4
|
+
|
5
|
+
**DISCLAIMER: Alpha status, YMMV!**
|
6
|
+
|
7
|
+
I am lazy as hell, and wanted to be able to install [PhantomJS](http://phantomjs.org) via Rubygems/Bundler when using [poltergeist](https://github.com/jonleighton/poltergeist).
|
8
|
+
|
9
|
+
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
|
10
|
+
install the prebuilt packages suitable for the current plattform (currently Linux 32/64 or OS X supported).
|
11
|
+
|
12
|
+
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`.
|
13
|
+
|
14
|
+
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.
|
15
|
+
|
16
|
+
**TL;DR:** Instead of manually installing phantomjs on your machines, use this gem. It will take care of it.
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'phantomjs'
|
22
|
+
Phantomjs.path # => path to a phantom js executable suitable to your current platform. Will install before return when not installed yet.
|
23
|
+
|
24
|
+
# Or run phantomjs with the passed arguments:
|
25
|
+
Phantomjs.run('./path/to/script.js') # => returns stdout
|
26
|
+
|
27
|
+
# Also takes a block to receive each line of output:
|
28
|
+
Phantomjs.run('./path/to/script.js') { |line| puts line }
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage with Poltergeist/Capybara
|
32
|
+
|
33
|
+
Add this to your `Gemfile`:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
group :test do
|
37
|
+
gem 'poltergeist'
|
38
|
+
gem 'phantomjs2', :require => 'phantomjs/poltergeist'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
This will automatically require (and install) phantomjs and configure Capybara in the same way as noted below for manual setup.
|
43
|
+
|
44
|
+
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.
|
45
|
+
|
46
|
+
### Manual setup
|
47
|
+
|
48
|
+
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:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'phantomjs' # <-- Not required if your app does Bundler.require automatically (e.g. when using Rails)
|
52
|
+
Capybara.register_driver :poltergeist do |app|
|
53
|
+
Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Check out [the poltergeist docs](https://www.ruby-toolbox.com/gems/phantomjs) for all the options you can pass in there.
|
58
|
+
|
59
|
+
## A note about versions.
|
60
|
+
|
61
|
+
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.
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
**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. :)
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
72
|
+
|
73
|
+
## Copyright
|
74
|
+
|
75
|
+
(c) 2013-2014 Christoph Olszowka
|
76
|
+
|
77
|
+
Note that this project merely simplifies the installation of the entirely separate PhantomJS project
|
78
|
+
via a Ruby gem. You can find the license information for PhantomJS at http://phantomjs.org/
|
data/Rakefile
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
module Phantomjs
|
2
|
+
class Platform
|
3
|
+
class << self
|
4
|
+
def host_os
|
5
|
+
RbConfig::CONFIG['host_os']
|
6
|
+
end
|
7
|
+
|
8
|
+
def architecture
|
9
|
+
RbConfig::CONFIG['host_cpu']
|
10
|
+
end
|
11
|
+
|
12
|
+
def temp_path
|
13
|
+
ENV['TMPDIR'] || ENV['TEMP'] || '/tmp'
|
14
|
+
end
|
15
|
+
|
16
|
+
def phantomjs_path
|
17
|
+
if system_phantomjs_installed?
|
18
|
+
system_phantomjs_path
|
19
|
+
else
|
20
|
+
File.expand_path File.join(Phantomjs.base_dir, platform, 'bin/phantomjs')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def system_phantomjs_path
|
25
|
+
`which phantomjs`.delete("\n")
|
26
|
+
rescue
|
27
|
+
end
|
28
|
+
|
29
|
+
def system_phantomjs_version
|
30
|
+
`phantomjs --version`.delete("\n") if system_phantomjs_path.length > 4.2
|
31
|
+
rescue
|
32
|
+
end
|
33
|
+
|
34
|
+
def system_phantomjs_installed?
|
35
|
+
system_phantomjs_version == Phantomjs.version
|
36
|
+
end
|
37
|
+
|
38
|
+
def installed?
|
39
|
+
File.exist?(phantomjs_path) || system_phantomjs_installed?
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO: Clean this up, it looks like a pile of...
|
43
|
+
def install!
|
44
|
+
STDERR.puts "Phantomjs does not appear to be installed in #{phantomjs_path}, installing!"
|
45
|
+
FileUtils.mkdir_p Phantomjs.base_dir
|
46
|
+
|
47
|
+
# Purge temporary directory if it is still hanging around from previous installs,
|
48
|
+
# then re-create it.
|
49
|
+
temp_dir = File.join(temp_path, 'phantomjs_install')
|
50
|
+
FileUtils.rm_rf temp_dir
|
51
|
+
FileUtils.mkdir_p temp_dir
|
52
|
+
|
53
|
+
Dir.chdir temp_dir do
|
54
|
+
unless system "curl -L -O #{package_url} #{curl_proxy_options}" or system "wget #{package_url} #{wget_proxy_options}"
|
55
|
+
raise "\n\nFailed to load phantomjs! :(\nYou need to have cURL or wget installed on your system.\nIf you have, the source of phantomjs might be unavailable: #{package_url}\n\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
case package_url.split('.').last
|
59
|
+
when 'bz2'
|
60
|
+
system "bunzip2 #{File.basename(package_url)}"
|
61
|
+
system "tar xf #{File.basename(package_url).sub(/\.bz2$/, '')}"
|
62
|
+
when 'zip'
|
63
|
+
system "unzip #{File.basename(package_url)}"
|
64
|
+
else
|
65
|
+
raise "Unknown compression format for #{File.basename(package_url)}"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Find the phantomjs build we just extracted
|
69
|
+
extracted_dir = Dir['phantomjs*'].find { |path| File.directory?(path) }
|
70
|
+
|
71
|
+
# Move the extracted phantomjs build to $HOME/.phantomjs/version/platform
|
72
|
+
if FileUtils.mv extracted_dir, File.join(Phantomjs.base_dir, platform)
|
73
|
+
STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Clean up remaining files in tmp
|
77
|
+
if FileUtils.rm_rf temp_dir
|
78
|
+
STDOUT.puts 'Removed temporarily downloaded files.'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
raise 'Failed to install phantomjs. Sorry :(' unless File.exist?(phantomjs_path)
|
83
|
+
end
|
84
|
+
|
85
|
+
def ensure_installed!
|
86
|
+
install! unless installed?
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def curl_proxy_options
|
92
|
+
return '' if Phantomjs.proxy_host.nil? && Phantomjs.proxy_port.nil?
|
93
|
+
"-x #{Phantomjs.proxy_host}:#{Phantomjs.proxy_port}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def wget_proxy_options
|
97
|
+
return '' if Phantomjs.proxy_host.nil? && Phantomjs.proxy_port.nil?
|
98
|
+
"-e use_proxy=yes -e http_proxy=#{Phantomjs.proxy_host}:#{Phantomjs.proxy_port}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class Linux64 < Platform
|
103
|
+
class << self
|
104
|
+
def useable?
|
105
|
+
host_os.include?('linux') and architecture.include?('x86_64')
|
106
|
+
end
|
107
|
+
|
108
|
+
def platform
|
109
|
+
'x86_64-linux'
|
110
|
+
end
|
111
|
+
|
112
|
+
def package_url
|
113
|
+
'https://github.com/bprodoehl/phantomjs/releases/download/v2.0.0-20150528/phantomjs-2.0.0-20150528-u1404-x86_64.zip'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Linux32 < Platform
|
119
|
+
class << self
|
120
|
+
def useable?
|
121
|
+
host_os.include?('linux') and (architecture.include?('x86_32') or architecture.include?('i686'))
|
122
|
+
end
|
123
|
+
|
124
|
+
def platform
|
125
|
+
'x86_32-linux'
|
126
|
+
end
|
127
|
+
|
128
|
+
def package_url
|
129
|
+
'https://s3-us-west-2.amazonaws.com/phantomjs-bin/phantomjs-2.0.0-debian7.8_linux-i686.tar.bz2'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class OsX < Platform
|
135
|
+
class << self
|
136
|
+
def useable?
|
137
|
+
host_os.include?('darwin')
|
138
|
+
end
|
139
|
+
|
140
|
+
def platform
|
141
|
+
'darwin'
|
142
|
+
end
|
143
|
+
|
144
|
+
def package_url
|
145
|
+
'https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.0.0-macosx.zip'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class Win32 < Platform
|
151
|
+
class << self
|
152
|
+
def useable?
|
153
|
+
host_os.include?('mingw32') and architecture.include?('i686')
|
154
|
+
end
|
155
|
+
|
156
|
+
def platform
|
157
|
+
'win32'
|
158
|
+
end
|
159
|
+
|
160
|
+
def phantomjs_path
|
161
|
+
if system_phantomjs_installed?
|
162
|
+
system_phantomjs_path
|
163
|
+
else
|
164
|
+
File.expand_path File.join(Phantomjs.base_dir, platform, 'phantomjs.exe')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def package_url
|
169
|
+
'https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.0.0-windows.zip'
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'phantomjs'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'capybara/poltergeist'
|
6
|
+
rescue => LoadError
|
7
|
+
raise 'Poltergeist support requires the poltergeist gem to be available.'
|
8
|
+
end
|
9
|
+
|
10
|
+
Phantomjs.path # Force install on require
|
11
|
+
Capybara.register_driver :poltergeist do |app|
|
12
|
+
Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
|
13
|
+
end
|
data/lib/phantomjs.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'phantomjs/version'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Phantomjs
|
5
|
+
UnknownPlatform = Class.new StandardError
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :proxy_host, :proxy_port
|
9
|
+
|
10
|
+
def available_platforms
|
11
|
+
@available_platforms ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def base_dir
|
15
|
+
@base_dir ||= File.join(File.expand_path('~'), '.phantomjs', version)
|
16
|
+
end
|
17
|
+
|
18
|
+
def base_dir=(dir)
|
19
|
+
@base_dir = dir
|
20
|
+
end
|
21
|
+
|
22
|
+
def version
|
23
|
+
Phantomjs::VERSION.split('.')[0..-2].join('.')
|
24
|
+
end
|
25
|
+
|
26
|
+
def path
|
27
|
+
@path ||= platform.phantomjs_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def platform
|
31
|
+
if platform = available_platforms.find { |p| p.useable? }
|
32
|
+
platform.ensure_installed!
|
33
|
+
platform
|
34
|
+
else
|
35
|
+
raise UnknownPlatform, "Could not find an appropriate PhantomJS library for your platform (#{RUBY_PLATFORM} :( Please install manually."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Removes the local phantomjs copy
|
40
|
+
def implode!
|
41
|
+
FileUtils.rm_rf File.join(File.expand_path('~'), '.phantomjs')
|
42
|
+
end
|
43
|
+
|
44
|
+
# Clears cached state. Primarily useful for testing.
|
45
|
+
def reset!
|
46
|
+
@base_dir = @path = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Run phantomjs with the given arguments, and either
|
50
|
+
# return the stdout or yield each line to the passed block.
|
51
|
+
def run(*args, &block)
|
52
|
+
IO.popen([path, *args]) do |io|
|
53
|
+
block ? io.each(&block) : io.read
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
require 'phantomjs/platform'
|
60
|
+
Phantomjs.available_platforms << Phantomjs::Platform::Linux32
|
61
|
+
Phantomjs.available_platforms << Phantomjs::Platform::Linux64
|
62
|
+
Phantomjs.available_platforms << Phantomjs::Platform::OsX
|
63
|
+
Phantomjs.available_platforms << Phantomjs::Platform::Win32
|
data/phantomjs.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/phantomjs/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Christoph Olszowka', 'Mikhail Grachev']
|
6
|
+
gem.email = ['christoph at olszowka.de', 'work@mgrachev.com']
|
7
|
+
gem.description = %q{Auto-install phantomjs on demand for current platform. Comes with poltergeist integration.}
|
8
|
+
gem.summary = %q{Auto-install phantomjs on demand for current platform. Comes with poltergeist integration.}
|
9
|
+
gem.homepage = 'https://github.com/mgrachev/phantomjs-gem'
|
10
|
+
gem.license = 'MIT'
|
11
|
+
|
12
|
+
gem.add_development_dependency 'poltergeist', '~> 1.5'
|
13
|
+
gem.add_development_dependency 'capybara', '~> 2.4'
|
14
|
+
gem.add_development_dependency 'rspec', '~> 2.99'
|
15
|
+
gem.add_development_dependency 'simplecov'
|
16
|
+
gem.add_development_dependency 'rake'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($\)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.name = 'phantomjs2'
|
22
|
+
gem.require_paths = ['lib']
|
23
|
+
gem.version = Phantomjs::VERSION
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'phantomjs/poltergeist'
|
3
|
+
|
4
|
+
HTML_RESPONSE = <<HTML
|
5
|
+
<html>
|
6
|
+
<head></head>
|
7
|
+
<body>
|
8
|
+
<h1>Hello</h1>
|
9
|
+
<div id="js">NO JS :(</div>
|
10
|
+
<script type="text/javascript">
|
11
|
+
document.getElementById('js').innerHTML = 'OMG JS!';
|
12
|
+
</script>
|
13
|
+
</body>
|
14
|
+
</html>
|
15
|
+
HTML
|
16
|
+
Capybara.app = lambda {|env| [200, {"Content-Type" => "text/html"}, [HTML_RESPONSE]] }
|
17
|
+
Capybara.default_driver = :poltergeist
|
18
|
+
|
19
|
+
describe Phantomjs do
|
20
|
+
describe 'A HTTP request using capybara/poltergeist' do
|
21
|
+
include Capybara::DSL
|
22
|
+
|
23
|
+
before { visit '/' }
|
24
|
+
it "has displayed static html content" do
|
25
|
+
within('h1') { page.should have_content('Hello') }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has processed javascript" do
|
29
|
+
within "#js" do
|
30
|
+
page.should_not have_content('NO JS :(')
|
31
|
+
page.should have_content('OMG JS!')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".run" do
|
37
|
+
it "runs phantomjs binary with the correct arguments" do
|
38
|
+
script = File.expand_path('./spec/runner.js')
|
39
|
+
result = Phantomjs.run(script, 'foo1', 'foo2')
|
40
|
+
result.should eq("bar foo1\nbar foo2\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "accepts a block that will get called for each line of output" do
|
44
|
+
lines = []
|
45
|
+
script = File.expand_path('./spec/runner.js')
|
46
|
+
Phantomjs.run(script, 'foo1', 'foo2') { |line| lines << line }
|
47
|
+
lines.should eq(["bar foo1\n", "bar foo2\n"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phantomjs::Platform do
|
4
|
+
before(:each) { Phantomjs.reset! }
|
5
|
+
describe "with a system install present" do
|
6
|
+
describe "#system_phantomjs_installed?" do
|
7
|
+
it "is true when the system version matches Phantomjs.version" do
|
8
|
+
Phantomjs::Platform.should_receive(:system_phantomjs_version).and_return(Phantomjs.version)
|
9
|
+
expect(Phantomjs::Platform.system_phantomjs_installed?).to be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "is false when the system version does not match Phantomjs.version" do
|
13
|
+
Phantomjs::Platform.should_receive(:system_phantomjs_version).and_return('1.2.3')
|
14
|
+
expect(Phantomjs::Platform.system_phantomjs_installed?).to be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is false when there's no system version" do
|
18
|
+
Phantomjs::Platform.should_receive(:system_phantomjs_version).and_return(nil)
|
19
|
+
expect(Phantomjs::Platform.system_phantomjs_installed?).to be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "on a 64 bit linux" do
|
25
|
+
before do
|
26
|
+
Phantomjs::Platform.stub(:host_os).and_return('linux-gnu')
|
27
|
+
Phantomjs::Platform.stub(:architecture).and_return('x86_64')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "reports the Linux64 Platform as useable" do
|
31
|
+
Phantomjs::Platform::Linux64.should be_useable
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "without system install" do
|
35
|
+
before(:each) { Phantomjs::Platform.stub(:system_phantomjs_version).and_return(nil) }
|
36
|
+
|
37
|
+
it "returns the correct phantom js executable path for the platform" do
|
38
|
+
Phantomjs.path.should =~ /x86_64-linux\/bin\/phantomjs$/
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "with system install" do
|
43
|
+
before(:each) do
|
44
|
+
Phantomjs::Platform.stub(:system_phantomjs_version).and_return(Phantomjs.version)
|
45
|
+
Phantomjs::Platform.stub(:system_phantomjs_path).and_return('/tmp/path')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns the correct phantom js executable path for the platform" do
|
49
|
+
expect(Phantomjs.path).to be == '/tmp/path'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "reports the Linux32 platform as unuseable" do
|
54
|
+
Phantomjs::Platform::Linux32.should_not be_useable
|
55
|
+
end
|
56
|
+
|
57
|
+
it "reports the Darwin platform as unuseable" do
|
58
|
+
Phantomjs::Platform::OsX.should_not be_useable
|
59
|
+
end
|
60
|
+
|
61
|
+
it "reports the Win32 Platform as unuseable" do
|
62
|
+
Phantomjs::Platform::Win32.should_not be_useable
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "on a 32 bit linux" do
|
67
|
+
before do
|
68
|
+
Phantomjs::Platform.stub(:host_os).and_return('linux-gnu')
|
69
|
+
Phantomjs::Platform.stub(:architecture).and_return('x86_32')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "reports the Linux32 Platform as useable" do
|
73
|
+
Phantomjs::Platform::Linux32.should be_useable
|
74
|
+
end
|
75
|
+
|
76
|
+
it "reports another Linux32 Platform as useable" do
|
77
|
+
Phantomjs::Platform.stub(:host_os).and_return('linux-gnu')
|
78
|
+
Phantomjs::Platform.stub(:architecture).and_return('i686')
|
79
|
+
Phantomjs::Platform::Linux32.should be_useable
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "without system install" do
|
83
|
+
before(:each) { Phantomjs::Platform.stub(:system_phantomjs_version).and_return(nil) }
|
84
|
+
|
85
|
+
it "returns the correct phantom js executable path for the platform" do
|
86
|
+
Phantomjs.path.should =~ /x86_32-linux\/bin\/phantomjs$/
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "with system install" do
|
91
|
+
before(:each) do
|
92
|
+
Phantomjs::Platform.stub(:system_phantomjs_version).and_return(Phantomjs.version)
|
93
|
+
Phantomjs::Platform.stub(:system_phantomjs_path).and_return('/tmp/path')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns the correct phantom js executable path for the platform" do
|
97
|
+
expect(Phantomjs.path).to be == '/tmp/path'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "reports the Linux64 platform as unuseable" do
|
102
|
+
Phantomjs::Platform::Linux64.should_not be_useable
|
103
|
+
end
|
104
|
+
|
105
|
+
it "reports the Darwin platform as unuseable" do
|
106
|
+
Phantomjs::Platform::OsX.should_not be_useable
|
107
|
+
end
|
108
|
+
|
109
|
+
it "reports the Win32 Platform as unuseable" do
|
110
|
+
Phantomjs::Platform::Win32.should_not be_useable
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "on OS X" do
|
115
|
+
before do
|
116
|
+
Phantomjs::Platform.stub(:host_os).and_return('darwin')
|
117
|
+
Phantomjs::Platform.stub(:architecture).and_return('x86_64')
|
118
|
+
end
|
119
|
+
|
120
|
+
it "reports the Darwin platform as useable" do
|
121
|
+
Phantomjs::Platform::OsX.should be_useable
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "without system install" do
|
125
|
+
before(:each) { Phantomjs::Platform.stub(:system_phantomjs_version).and_return(nil) }
|
126
|
+
|
127
|
+
it "returns the correct phantom js executable path for the platform" do
|
128
|
+
Phantomjs.path.should =~ /darwin\/bin\/phantomjs$/
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "with system install" do
|
133
|
+
before(:each) do
|
134
|
+
Phantomjs::Platform.stub(:system_phantomjs_version).and_return(Phantomjs.version)
|
135
|
+
Phantomjs::Platform.stub(:system_phantomjs_path).and_return('/tmp/path')
|
136
|
+
end
|
137
|
+
|
138
|
+
it "returns the correct phantom js executable path for the platform" do
|
139
|
+
expect(Phantomjs.path).to be == '/tmp/path'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "reports the Linux32 Platform as unuseable" do
|
144
|
+
Phantomjs::Platform::Linux32.should_not be_useable
|
145
|
+
end
|
146
|
+
|
147
|
+
it "reports the Linux64 platform as unuseable" do
|
148
|
+
Phantomjs::Platform::Linux64.should_not be_useable
|
149
|
+
end
|
150
|
+
|
151
|
+
it "reports the Win32 Platform as unuseable" do
|
152
|
+
Phantomjs::Platform::Win32.should_not be_useable
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "on Windows" do
|
157
|
+
before do
|
158
|
+
Phantomjs::Platform.stub(:host_os).and_return('mingw32')
|
159
|
+
Phantomjs::Platform.stub(:architecture).and_return('i686')
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "without system install" do
|
163
|
+
before(:each) { Phantomjs::Platform.stub(:system_phantomjs_version).and_return(nil) }
|
164
|
+
|
165
|
+
it "returns the correct phantom js executable path for the platform" do
|
166
|
+
Phantomjs.path.should =~ /win32\/phantomjs.exe$/
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "with system install" do
|
171
|
+
before(:each) do
|
172
|
+
Phantomjs::Platform.stub(:system_phantomjs_version).and_return(Phantomjs.version)
|
173
|
+
Phantomjs::Platform.stub(:system_phantomjs_path).and_return("#{ENV['TEMP']}/path")
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns the correct phantom js executable path for the platform" do
|
177
|
+
expect(Phantomjs.path).to be == "#{ENV['TEMP']}/path"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
it "reports the Darwin platform as unuseable" do
|
182
|
+
Phantomjs::Platform::OsX.should_not be_useable
|
183
|
+
end
|
184
|
+
|
185
|
+
it "reports the Linux32 Platform as unuseable" do
|
186
|
+
Phantomjs::Platform::Linux32.should_not be_useable
|
187
|
+
end
|
188
|
+
|
189
|
+
it "reports the Linux64 platform as unuseable" do
|
190
|
+
Phantomjs::Platform::Linux64.should_not be_useable
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'on an unknown platform' do
|
195
|
+
before do
|
196
|
+
Phantomjs::Platform.stub(:host_os).and_return('foobar')
|
197
|
+
end
|
198
|
+
|
199
|
+
it "raises an UnknownPlatform error" do
|
200
|
+
-> { Phantomjs.platform }.should raise_error(Phantomjs::UnknownPlatform)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
data/spec/runner.js
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phantomjs2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christoph Olszowka
|
8
|
+
- Mikhail Grachev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: poltergeist
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.5'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: capybara
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.4'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.99'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.99'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: simplecov
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Auto-install phantomjs on demand for current platform. Comes with poltergeist
|
85
|
+
integration.
|
86
|
+
email:
|
87
|
+
- christoph at olszowka.de
|
88
|
+
- work@mgrachev.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".simplecov"
|
96
|
+
- ".travis.yml"
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- lib/phantomjs.rb
|
102
|
+
- lib/phantomjs/platform.rb
|
103
|
+
- lib/phantomjs/poltergeist.rb
|
104
|
+
- lib/phantomjs/version.rb
|
105
|
+
- phantomjs.gemspec
|
106
|
+
- spec/phantomjs_spec.rb
|
107
|
+
- spec/platform_spec.rb
|
108
|
+
- spec/runner.js
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
homepage: https://github.com/mgrachev/phantomjs-gem
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.7
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Auto-install phantomjs on demand for current platform. Comes with poltergeist
|
134
|
+
integration.
|
135
|
+
test_files:
|
136
|
+
- spec/phantomjs_spec.rb
|
137
|
+
- spec/platform_spec.rb
|
138
|
+
- spec/runner.js
|
139
|
+
- spec/spec_helper.rb
|