Permalink
Browse files

run executer when needed, kill on exit, use childprocess so capybara-…

…zombie works on different platforms
  • Loading branch information...
1 parent bb17d6d commit a6c32915636efc9f3bb72eeb5af228a36820672c @boblail boblail committed with vinibaggio Feb 12, 2011
Showing with 63 additions and 14 deletions.
  1. +16 −14 Gemfile.lock
  2. +1 −0 capybara-zombie.gemspec
  3. +10 −0 lib/capybara/driver/zombie_driver.rb
  4. +36 −0 lib/capybara/zombie/executer.rb
View
@@ -3,12 +3,13 @@ PATH
specs:
capybara-zombie (0.0.1)
capybara (~> 0.4.1)
+ childprocess (~> 0.1.7)
multi_json (~> 0.0.5)
GEM
remote: http://rubygems.org/
specs:
- capybara (0.4.1.1)
+ capybara (0.4.1.2)
celerity (>= 0.7.9)
culerity (>= 0.2.4)
mime-types (>= 1.16)
@@ -18,14 +19,14 @@ GEM
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.3)
celerity (0.8.7)
- childprocess (0.1.6)
+ childprocess (0.1.7)
ffi (~> 0.6.3)
columnize (0.3.2)
culerity (0.2.15)
diff-lcs (1.1.2)
ffi (0.6.3)
rake (>= 0.8.7)
- json_pure (1.4.6)
+ json_pure (1.5.1)
linecache (0.43)
mime-types (1.16)
multi_json (0.0.5)
@@ -34,14 +35,14 @@ GEM
rack-test (0.5.7)
rack (>= 1.0)
rake (0.8.7)
- rspec (2.3.0)
- rspec-core (~> 2.3.0)
- rspec-expectations (~> 2.3.0)
- rspec-mocks (~> 2.3.0)
- rspec-core (2.3.1)
- rspec-expectations (2.3.0)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.3.0)
+ rspec-mocks (2.5.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
@@ -53,13 +54,13 @@ GEM
ffi (~> 0.6.3)
json_pure
rubyzip
- sinatra (1.1.0)
+ sinatra (1.1.2)
rack (~> 1.1)
- tilt (~> 1.1)
- tilt (1.1)
+ tilt (~> 1.2)
+ tilt (1.2.2)
xpath (0.1.3)
nokogiri (~> 1.3)
- yajl-ruby (0.7.8)
+ yajl-ruby (0.7.9)
PLATFORMS
ruby
@@ -68,6 +69,7 @@ DEPENDENCIES
bundler (~> 1.0)
capybara (~> 0.4.1)
capybara-zombie!
+ childprocess (~> 0.1.7)
multi_json (~> 0.0.5)
rspec (~> 2.0)
ruby-debug
View
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("capybara", "~> 0.4.1")
s.add_runtime_dependency("multi_json", "~> 0.0.5")
+ s.add_runtime_dependency("childprocess", "~> 0.1.7")
s.add_development_dependency("bundler", "~> 1.0")
s.add_development_dependency("rspec", "~> 2.0")
@@ -1,4 +1,5 @@
require "capybara/zombie/helpers"
+require "capybara/zombie/executer"
class Capybara::Driver::Zombie < Capybara::Driver::Base
include Capybara::Zombie::Helpers
@@ -140,11 +141,20 @@ def [](key)
attr_reader :app, :rack_server, :options
+ class << self
+ def zombie
+ @zombie ||= Capybara::Zombie::Executer.new
+ end
+ end
+
def initialize(app, options={})
@app = app
@options = options
@rack_server = Capybara::Server.new(@app)
@rack_server.boot if Capybara.run_server
+
+ self.class.zombie.animate!
+ at_exit do; self.class.zombie.kill; end
end
def visit(path)
@@ -0,0 +1,36 @@
+require "childprocess"
+
+module Capybara
+ module Zombie
+ class Executer
+
+ def animate!
+ unless self.process
+ # puts "starting zombie..."
+ self.process = ChildProcess.new("env node #{executer_path}")
+ self.process.start
+ sleep 0.5
+ raise("Zombie is not running") unless self.process.alive?
+ end
+ end
+
+ def kill
+ if self.process
+ # puts "killing zombie..."
+ self.process.stop if self.process.alive?
+ self.process = nil
+ sleep 0.5
+ end
+ end
+
+ protected
+
+ attr_accessor :process
+
+ def executer_path
+ @executer_path ||= File.join(File.expand_path(File.dirname(__FILE__)), "executer.js")
+ end
+
+ end
+ end
+end

0 comments on commit a6c3291

Please sign in to comment.