mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
Remove posix-spawn dependency.
posix-spawn relies on a C extension. This does work under JRuby, but it won't work on Travis CI as they disallow JRuby C extensions, as they are considered to not be a good practice. Instead we are using either Process.spawn on Ruby 1.9, or the childprocess gem on Ruby 1.8. childprocess uses native JVM APIs on JRuby, and fork+exec on others.
This commit is contained in:
parent
02f2a7277e
commit
98c3bb564f
6 changed files with 26 additions and 10 deletions
|
@ -11,6 +11,7 @@ module Capybara
|
|||
autoload :Client, 'capybara/poltergeist/client'
|
||||
autoload :Util, 'capybara/poltergeist/util'
|
||||
autoload :Inspector, 'capybara/poltergeist/inspector'
|
||||
autoload :Spawn, 'capybara/poltergeist/spawn'
|
||||
|
||||
require 'capybara/poltergeist/errors'
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'posix/spawn'
|
||||
|
||||
module Capybara::Poltergeist
|
||||
class Client
|
||||
PHANTOMJS_SCRIPT = File.expand_path('../client/compiled/main.js', __FILE__)
|
||||
|
@ -18,12 +16,14 @@ module Capybara::Poltergeist
|
|||
@port = port
|
||||
@inspector = inspector
|
||||
@path = path || PHANTOMJS_NAME
|
||||
at_exit { stop }
|
||||
|
||||
pid = Process.pid
|
||||
at_exit { stop if Process.pid == pid }
|
||||
end
|
||||
|
||||
def start
|
||||
check_phantomjs_version
|
||||
@pid = POSIX::Spawn.spawn(command)
|
||||
@pid = Spawn.spawn(*command)
|
||||
end
|
||||
|
||||
def stop
|
||||
|
@ -55,7 +55,7 @@ module Capybara::Poltergeist
|
|||
|
||||
parts << PHANTOMJS_SCRIPT
|
||||
parts << port
|
||||
parts.join(" ")
|
||||
parts
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'posix/spawn'
|
||||
|
||||
module Capybara::Poltergeist
|
||||
class Inspector
|
||||
BROWSERS = %w(chromium chromium-browser google-chrome safari)
|
||||
|
@ -26,7 +24,7 @@ module Capybara::Poltergeist
|
|||
|
||||
def open
|
||||
if browser
|
||||
POSIX::Spawn.spawn("#{browser} #{url}")
|
||||
Spawn.spawn(browser, url)
|
||||
else
|
||||
raise Error, "Could not find a browser executable to open #{url}. " \
|
||||
"You can specify one manually using e.g. `:inspector => 'chromium'` " \
|
||||
|
|
17
lib/capybara/poltergeist/spawn.rb
Normal file
17
lib/capybara/poltergeist/spawn.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'childprocess'
|
||||
|
||||
module Capybara::Poltergeist
|
||||
module Spawn
|
||||
def self.spawn(*args)
|
||||
args = args.map(&:to_s)
|
||||
|
||||
if RUBY_VERSION >= "1.9"
|
||||
Process.spawn(*args)
|
||||
else
|
||||
process = ChildProcess.build(*args)
|
||||
process.start
|
||||
process.pid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.add_dependency "capybara", "~> 1.0"
|
||||
s.add_dependency "json", "~> 1.6"
|
||||
s.add_dependency "posix-spawn", "~> 0.3"
|
||||
s.add_dependency "childprocess", "~> 0.3"
|
||||
s.add_dependency "http_parser.rb", "~> 0.5.3"
|
||||
s.add_dependency "faye-websocket", "~> 0.4", ">= 0.4.2"
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module Capybara::Poltergeist
|
|||
|
||||
it 'can be opened' do
|
||||
subject.stub(:port => 1234, :browser => 'chromium')
|
||||
POSIX::Spawn.should_receive(:spawn).with("chromium http://localhost:1234/")
|
||||
Spawn.should_receive(:spawn).with("chromium", "http://localhost:1234/")
|
||||
subject.open
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue