nurettin-phantomjs 1.7.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.simplecov ADDED
@@ -0,0 +1 @@
1
+ SimpleCov.start
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phantomjs.gemspec
4
+ gemspec
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) 2012 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,68 @@
1
+ # Phantomjs as a Rubygem
2
+
3
+ **DISCLAIMER: Alpha status, YMMV!**
4
+
5
+ I am lazy as hell, and wanted to be able to install [PhantomJS](http://phantomjs.org) via Rubygems/Bundler
6
+ when using [poltergeist](https://github.com/jonleighton/poltergeist).
7
+
8
+ It keeps installations of phantomjs in `$HOME/.phantomjs/VERSION/PLATFORM`. When you call `Phantomjs.path`, it
9
+ 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
+ You will need `cURL` or `wget` on your system. For extraction, `bunzip2` and `tar` are required on Linux, and `unzip`
13
+ on OS X. They should be installed already.
14
+
15
+ **TL;DR:** Instead of manually installing phantomjs on your machines, use this gem. It will take care of it.
16
+
17
+ ## Example
18
+
19
+ require 'phantomjs'
20
+ Phantomjs.path # => path to a phantom js executable suitable to your current platform. Will install before return when not installed yet.
21
+
22
+ ## Usage with Poltergeist/Capybara
23
+
24
+ Add this to your `Gemfile`:
25
+
26
+ group :test do
27
+ gem 'phantomjs', :require => 'phantomjs/poltergeist'
28
+ end
29
+
30
+ This will automatically require (and install) phantomjs and configure Capybara in the same way as noted below for
31
+ manual setup
32
+
33
+ ### Manual setup
34
+
35
+ Add `gem 'phantomjs', :group => :test` to your `Gemfile` and run `bundle`. In your test/spec helper, re-configure
36
+ the Poltergeist capybara driver to use the phantomjs package from this gem:
37
+
38
+ require 'phantomjs' # <-- Not required if your app does Bundler.require automatically (e.g. when using Rails)
39
+ Capybara.register_driver :poltergeist do |app|
40
+ Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
41
+ end
42
+
43
+ Check out [the poltergeist docs](https://www.ruby-toolbox.com/gems/phantomjs) for all the options you can pass in there.
44
+
45
+ ## A note about versions.
46
+
47
+ The gem version consists of 4 digits: The first 3 indicate the phantomjs release installed via this gem,
48
+ the last one is the internal version of this gem, in case I screw things up and need to push another release
49
+ before
50
+
51
+ ## Contributing
52
+
53
+ **Warning**: The `spec_helper` calls `Phantomjs.implode` when it is loaded, which purges the `~/.phantomjs`
54
+ directory. This is no bad thing, it just means every time you run the specs you'll download and install all
55
+ three packages over, so tread with caution please :)
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
62
+
63
+ ## Copyright
64
+
65
+ (c) 2012 Christoph Olszowka
66
+
67
+ 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/
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/phantomjs.rb ADDED
@@ -0,0 +1,48 @@
1
+ require "phantomjs/version"
2
+ require 'fileutils'
3
+
4
+ module Phantomjs
5
+ class UnknownPlatform < StandardError; end;
6
+
7
+ class << self
8
+ def available_platforms
9
+ @available_platforms ||= []
10
+ end
11
+
12
+ def base_dir
13
+ @base_dir ||= File.join(File.expand_path('~'), '.phantomjs', version)
14
+ end
15
+
16
+ def version
17
+ Phantomjs::VERSION.split('.')[0..-2].join('.')
18
+ end
19
+
20
+ def path
21
+ @path ||= platform.phantomjs_path
22
+ end
23
+
24
+ def platform
25
+ if platform = available_platforms.find {|p| p.useable? }
26
+ platform.ensure_installed!
27
+ platform
28
+ else
29
+ raise UnknownPlatform, "Could not find an appropriate PhantomJS library for your platform (#{RUBY_PLATFORM} :( Please install manually."
30
+ end
31
+ end
32
+
33
+ # Removes the local phantomjs copy
34
+ def implode!
35
+ FileUtils.rm_rf File.join(File.expand_path('~'), '.phantomjs')
36
+ end
37
+
38
+ # Clears cached state. Primarily useful for testing.
39
+ def reset!
40
+ @base_dir = @path = nil
41
+ end
42
+ end
43
+ end
44
+
45
+ require 'phantomjs/platform'
46
+ Phantomjs.available_platforms << Phantomjs::Platform::Linux32
47
+ Phantomjs.available_platforms << Phantomjs::Platform::Linux64
48
+ Phantomjs.available_platforms << Phantomjs::Platform::OsX
@@ -0,0 +1,116 @@
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 phantomjs_path
13
+ File.expand_path File.join(Phantomjs.base_dir, platform, 'bin/phantomjs')
14
+ end
15
+
16
+ def installed?
17
+ File.exist? phantomjs_path
18
+ end
19
+
20
+ # TODO: Clean this up, it looks like a pile of...
21
+ def install!
22
+ STDERR.puts "Phantomjs does not appear to be installed in #{phantomjs_path}, installing!"
23
+ FileUtils.mkdir_p Phantomjs.base_dir
24
+
25
+ # Purge temporary directory if it is still hanging around from previous installs,
26
+ # then re-create it.
27
+ temp_dir = File.join('/tmp', 'phantomjs_install')
28
+ FileUtils.rm_rf temp_dir
29
+ FileUtils.mkdir_p temp_dir
30
+
31
+ Dir.chdir temp_dir do
32
+ unless system "curl -O #{package_url}" or system "wget #{package_url}"
33
+ 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"
34
+ end
35
+
36
+ case package_url.split('.').last
37
+ when 'bz2'
38
+ system "bunzip2 #{File.basename(package_url)}"
39
+ system "tar xf #{File.basename(package_url).sub(/\.bz2$/, '')}"
40
+ when 'zip'
41
+ system "unzip #{File.basename(package_url)}"
42
+ else
43
+ raise "Unknown compression format for #{File.basename(package_url)}"
44
+ end
45
+
46
+ # Find the phantomjs build we just extracted
47
+ extracted_dir = Dir['phantomjs*'].find { |path| File.directory?(path) }
48
+
49
+ # Move the extracted phantomjs build to $HOME/.phantomjs/version/platform
50
+ if FileUtils.mv extracted_dir, File.join(Phantomjs.base_dir, platform)
51
+ STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
52
+ end
53
+
54
+ # Clean up remaining files in tmp
55
+ if FileUtils.rm_rf temp_dir
56
+ STDOUT.puts "Removed temporarily downloaded files."
57
+ end
58
+ end
59
+
60
+ raise "Failed to install phantomjs. Sorry :(" unless File.exist?(phantomjs_path)
61
+ end
62
+
63
+ def ensure_installed!
64
+ install! unless installed?
65
+ end
66
+ end
67
+
68
+ class Linux64 < Platform
69
+ class << self
70
+ def useable?
71
+ host_os.include?('linux') and architecture.include?('x86_64')
72
+ end
73
+
74
+ def platform
75
+ 'x86_64-linux'
76
+ end
77
+
78
+ def package_url
79
+ 'http://phantomjs.googlecode.com/files/phantomjs-1.7.0-linux-x86_64.tar.bz2'
80
+ end
81
+ end
82
+ end
83
+
84
+ class Linux32 < Platform
85
+ class << self
86
+ def useable?
87
+ host_os.include?('linux') and (architecture.include?('x86_32') or architecture.include?('i686'))
88
+ end
89
+
90
+ def platform
91
+ 'x86_32-linux'
92
+ end
93
+
94
+ def package_url
95
+ 'http://phantomjs.googlecode.com/files/phantomjs-1.7.0-linux-i686.tar.bz2'
96
+ end
97
+ end
98
+ end
99
+
100
+ class OsX < Platform
101
+ class << self
102
+ def useable?
103
+ host_os.include?('darwin')
104
+ end
105
+
106
+ def platform
107
+ 'darwin'
108
+ end
109
+
110
+ def package_url
111
+ 'http://phantomjs.googlecode.com/files/phantomjs-1.7.0-macosx.zip'
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ require 'phantomjs'
3
+ require 'capybara/poltergeist'
4
+ Phantomjs.path # Force install on require
5
+ Capybara.register_driver :poltergeist do |app|
6
+ Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
7
+ end
@@ -0,0 +1,3 @@
1
+ module Phantomjs
2
+ VERSION = "1.7.0.0"
3
+ end
data/phantomjs.gemspec ADDED
@@ -0,0 +1,22 @@
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"]
6
+ gem.email = ["christoph at olszowka.de"]
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/colszowka/phantomjs-gem"
10
+
11
+ gem.add_runtime_dependency 'poltergeist'
12
+
13
+ gem.add_development_dependency 'rspec', "~> 2.10.0"
14
+ gem.add_development_dependency 'simplecov'
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.name = "nurettin-phantomjs"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = Phantomjs::VERSION
22
+ end
@@ -0,0 +1,35 @@
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
+ include Capybara::DSL
21
+
22
+ describe 'A HTTP request using capybara/poltergeist' do
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
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phantomjs::Platform do
4
+ before(:each) { Phantomjs.reset! }
5
+ describe "on a 64 bit linux" do
6
+ before do
7
+ Phantomjs::Platform.stub(:host_os).and_return('linux-gnu')
8
+ Phantomjs::Platform.stub(:architecture).and_return('x86_64')
9
+ end
10
+
11
+ it "reports the Linux64 Platform as useable" do
12
+ Phantomjs::Platform::Linux64.should be_useable
13
+ end
14
+
15
+ it "returns the correct phantom js executable path for the platform" do
16
+ Phantomjs.path.should =~ /x86_64-linux\/bin\/phantomjs$/
17
+ end
18
+
19
+ it "reports the Linux32 platform as unuseable" do
20
+ Phantomjs::Platform::Linux32.should_not be_useable
21
+ end
22
+
23
+ it "reports the Darwin platform as unuseable" do
24
+ Phantomjs::Platform::OsX.should_not be_useable
25
+ end
26
+ end
27
+
28
+ describe "on a 32 bit linux" do
29
+ before do
30
+ Phantomjs::Platform.stub(:host_os).and_return('linux-gnu')
31
+ Phantomjs::Platform.stub(:architecture).and_return('x86_32')
32
+ end
33
+
34
+ it "reports the Linux32 Platform as useable" do
35
+ Phantomjs::Platform::Linux32.should be_useable
36
+ end
37
+
38
+ it "reports another Linux32 Platform as useable" do
39
+ Phantomjs::Platform.stub(:host_os).and_return('linux-gnu')
40
+ Phantomjs::Platform.stub(:architecture).and_return('i686')
41
+ Phantomjs::Platform::Linux32.should be_useable
42
+ end
43
+
44
+ it "returns the correct phantom js executable path for the platform" do
45
+ Phantomjs.path.should =~ /x86_32-linux\/bin\/phantomjs$/
46
+ end
47
+
48
+ it "reports the Linux64 platform as unuseable" do
49
+ Phantomjs::Platform::Linux64.should_not be_useable
50
+ end
51
+
52
+ it "reports the Darwin platform as unuseable" do
53
+ Phantomjs::Platform::OsX.should_not be_useable
54
+ end
55
+ end
56
+
57
+ describe "on OS X" do
58
+ before do
59
+ Phantomjs::Platform.stub(:host_os).and_return('darwin')
60
+ Phantomjs::Platform.stub(:architecture).and_return('x86_64')
61
+ end
62
+
63
+ it "reports the Darwin platform as useable" do
64
+ Phantomjs::Platform::OsX.should be_useable
65
+ end
66
+
67
+ it "returns the correct phantom js executable path for the platform" do
68
+ Phantomjs.path.should =~ /darwin\/bin\/phantomjs$/
69
+ end
70
+
71
+ it "reports the Linux32 Platform as unuseable" do
72
+ Phantomjs::Platform::Linux32.should_not be_useable
73
+ end
74
+
75
+ it "reports the Linux64 platform as unuseable" do
76
+ Phantomjs::Platform::Linux64.should_not be_useable
77
+ end
78
+ end
79
+
80
+ describe 'on an unknown platform' do
81
+ before do
82
+ Phantomjs::Platform.stub(:host_os).and_return('foobar')
83
+ end
84
+
85
+ it "raises an UnknownPlatform error" do
86
+ -> { Phantomjs.platform }.should raise_error(Phantomjs::UnknownPlatform)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'simplecov'
3
+ require 'bundler/setup'
4
+
5
+ require 'phantomjs'
6
+ require 'capybara/rspec'
7
+ require 'capybara/poltergeist'
8
+
9
+ Phantomjs.implode!
10
+
11
+ RSpec.configure do |config|
12
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nurettin-phantomjs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christoph Olszowka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: poltergeist
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.10.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.10.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Auto-install phantomjs on demand for current platform. Comes with poltergeist
63
+ integration.
64
+ email:
65
+ - christoph at olszowka.de
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - .simplecov
73
+ - Gemfile
74
+ - LICENSE
75
+ - README.md
76
+ - Rakefile
77
+ - lib/phantomjs.rb
78
+ - lib/phantomjs/platform.rb
79
+ - lib/phantomjs/poltergeist.rb
80
+ - lib/phantomjs/version.rb
81
+ - phantomjs.gemspec
82
+ - spec/phantomjs_spec.rb
83
+ - spec/platform_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: https://github.com/colszowka/phantomjs-gem
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.24
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Auto-install phantomjs on demand for current platform. Comes with poltergeist
109
+ integration.
110
+ test_files:
111
+ - spec/phantomjs_spec.rb
112
+ - spec/platform_spec.rb
113
+ - spec/spec_helper.rb