phantomjs 1.8.1.0 → 1.8.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/lib/phantomjs.rb +8 -0
- data/lib/phantomjs/version.rb +1 -1
- data/spec/phantomjs_spec.rb +17 -2
- data/spec/runner.js +3 -0
- metadata +6 -4
data/README.md
CHANGED
@@ -9,6 +9,9 @@ It keeps installations of phantomjs in `$HOME/.phantomjs/VERSION/PLATFORM`. When
|
|
9
9
|
will return the path to the phantomjs executable in there. If that is not present, it will first fetch and
|
10
10
|
install the prebuilt packages suitable for the current plattform (currently Linux 32/64 or OS X supported).
|
11
11
|
|
12
|
+
If there is a phantomjs executable in your `$PATH` that matches the version number packaged in this gem, this one
|
13
|
+
will be used instead of installing one in your `$HOME/.phantomjs`.
|
14
|
+
|
12
15
|
You will need `cURL` or `wget` on your system. For extraction, `bunzip2` and `tar` are required on Linux, and `unzip`
|
13
16
|
on OS X. They should be installed already.
|
14
17
|
|
@@ -19,6 +22,12 @@ on OS X. They should be installed already.
|
|
19
22
|
require 'phantomjs'
|
20
23
|
Phantomjs.path # => path to a phantom js executable suitable to your current platform. Will install before return when not installed yet.
|
21
24
|
|
25
|
+
# Or run phantomjs with the passed arguments:
|
26
|
+
Phantomjs.run('./path/to/script.js') # => returns stdout
|
27
|
+
|
28
|
+
# Also takes a block to receive each line of output:
|
29
|
+
Phantomjs.run('./path/to/script.js') { |line| puts line }
|
30
|
+
|
22
31
|
## Usage with Poltergeist/Capybara
|
23
32
|
|
24
33
|
Add this to your `Gemfile`:
|
@@ -65,4 +74,4 @@ three packages over, so tread with caution please :)
|
|
65
74
|
(c) 2012 Christoph Olszowka
|
66
75
|
|
67
76
|
Note that this project merely simplifies the installation of the entirely separate PhantomJS project
|
68
|
-
via a Ruby gem. You can find the license information for PhantomJS at http://http://phantomjs.org/
|
77
|
+
via a Ruby gem. You can find the license information for PhantomJS at http://http://phantomjs.org/
|
data/lib/phantomjs.rb
CHANGED
@@ -39,6 +39,14 @@ module Phantomjs
|
|
39
39
|
def reset!
|
40
40
|
@base_dir = @path = nil
|
41
41
|
end
|
42
|
+
|
43
|
+
# Run phantomjs with the given arguments, and either
|
44
|
+
# return the stdout or yield each line to the passed block.
|
45
|
+
def run(*args, &block)
|
46
|
+
IO.popen([path, *args]) do |io|
|
47
|
+
block ? io.each(&block) : io.read
|
48
|
+
end
|
49
|
+
end
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
data/lib/phantomjs/version.rb
CHANGED
data/spec/phantomjs_spec.rb
CHANGED
@@ -17,9 +17,9 @@ Capybara.app = lambda {|env| [200, {"Content-Type" => "text/html"}, [HTML_RESPON
|
|
17
17
|
Capybara.default_driver = :poltergeist
|
18
18
|
|
19
19
|
describe Phantomjs do
|
20
|
-
include Capybara::DSL
|
21
|
-
|
22
20
|
describe 'A HTTP request using capybara/poltergeist' do
|
21
|
+
include Capybara::DSL
|
22
|
+
|
23
23
|
before { visit '/' }
|
24
24
|
it "has displayed static html content" do
|
25
25
|
within('h1') { page.should have_content('Hello') }
|
@@ -32,4 +32,19 @@ describe Phantomjs do
|
|
32
32
|
end
|
33
33
|
end
|
34
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
|
35
50
|
end
|
data/spec/runner.js
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantomjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.1.
|
4
|
+
version: 1.8.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: poltergeist
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- phantomjs.gemspec
|
99
99
|
- spec/phantomjs_spec.rb
|
100
100
|
- spec/platform_spec.rb
|
101
|
+
- spec/runner.js
|
101
102
|
- spec/spec_helper.rb
|
102
103
|
homepage: https://github.com/colszowka/phantomjs-gem
|
103
104
|
licenses: []
|
@@ -113,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
segments:
|
115
116
|
- 0
|
116
|
-
hash:
|
117
|
+
hash: -4562338984157151972
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
none: false
|
119
120
|
requirements:
|
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: '0'
|
123
124
|
segments:
|
124
125
|
- 0
|
125
|
-
hash:
|
126
|
+
hash: -4562338984157151972
|
126
127
|
requirements: []
|
127
128
|
rubyforge_project:
|
128
129
|
rubygems_version: 1.8.25
|
@@ -133,4 +134,5 @@ summary: Auto-install phantomjs on demand for current platform. Comes with polte
|
|
133
134
|
test_files:
|
134
135
|
- spec/phantomjs_spec.rb
|
135
136
|
- spec/platform_spec.rb
|
137
|
+
- spec/runner.js
|
136
138
|
- spec/spec_helper.rb
|