class Teaspoon::Driver::Phantomjs
Public Class Methods
new(options = nil)
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 16 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::DriverOptionsError.new(types: "string, array or hash") end end
Public Instance Methods
run_specs(runner, url)
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 26 def run_specs(runner, url) run(*driver_options(url)) do |line| runner.process(line) if line && line.strip != "" end end
Protected Instance Methods
driver_options(url)
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 42 def driver_options(url) [ @options, escape_quotes(script), escape_quotes(url), Teaspoon.configuration.driver_timeout ].flatten.compact end
escape_quotes(string)
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 51 def escape_quotes(string) %{"#{string.gsub('"', '\"')}"} end
executable()
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 55 def executable return @executable if @executable @executable = defined?(::Phantomjs) ? ::Phantomjs.path : which("phantomjs") return @executable unless @executable.blank? raise Teaspoon::MissingDependencyError.new("Unable to locate phantomjs. Install it or use the phantomjs gem.") end
run(*args, &block)
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 34 def run(*args, &block) IO.popen([executable, *args].join(" ")) { |io| io.each(&block) } unless $?.nil? || $?.success? raise Teaspoon::DependencyError.new("Failed to use phantomjs, which exited with status code: #{$?.exitstatus}") end end
script()
click to toggle source
# File lib/teaspoon/driver/phantomjs.rb, line 62 def script File.expand_path("../phantomjs/runner.js", __FILE__) end