lib/teaspoon/drivers/phantomjs_driver.rb in teaspoon-0.7.9 vs lib/teaspoon/drivers/phantomjs_driver.rb in teaspoon-0.8.0
- old
+ new
@@ -1,47 +1,47 @@
-require "teaspoon/runner"
-require 'teaspoon/utility'
-
begin
require "phantomjs"
rescue LoadError
+ # if we can't load phantomjs, assume the cli is installed and in the path
end
module Teaspoon
module Drivers
- class PhantomjsDriver < BaseDriver
+ class PhantomjsDriver < Base
include Teaspoon::Utility
- def run_specs(suite, url, cli_options = nil)
- runner = Teaspoon::Runner.new(suite)
+ def initialize(options = nil)
+ options ||= []
+ case options
+ when Array then @options = options
+ when String then @options = options.split(" ")
+ when Hash then @options = options.map { |k, v| "--#{k}=#{v}" }
+ else raise Teaspoon::UnknownDriverOptions, "Unknown driver options -- supply a string, array or hash"
+ end
+ end
- run(*cli_arguments(url, cli_options)) do |line|
+ def run_specs(runner, url)
+ run(*driver_options(url)) do |line|
runner.process(line) if line && line.strip != ""
end
-
- runner.failure_count
end
protected
def run(*args, &block)
- IO.popen([executable, *args]) { |io|
- io.each(&block)
- }
+ IO.popen([executable, *args].join(' ')) { |io| io.each(&block) }
end
- def cli_arguments(url, cli_options)
- [cli_options.to_s.split(" "), script, url].flatten.compact
+ def driver_options(url)
+ [@options, script, url.shellescape, Teaspoon.configuration.driver_timeout].flatten.compact
end
def executable
- executable ||= which('phantomjs')
- executable = Phantomjs.path if executable.blank? && defined?(::Phantomjs)
- if executable.blank?
- STDOUT.print("Could not find PhantomJS. Install phantomjs or try the phantomjs gem.")
- exit(1)
- end
- executable
+ return @executable if @executable
+ @executable = which("phantomjs")
+ @executable = Phantomjs.path if @executable.blank? && defined?(::Phantomjs)
+ return @executable unless @executable.blank?
+ raise Teaspoon::MissingDependency, "Could not find PhantomJS. Install phantomjs or try the phantomjs gem."
end
def script
File.expand_path("../phantomjs/runner.js", __FILE__)
end