lib/jasmine/runners/phantom.rb in phantom_jasmine-0.0.6 vs lib/jasmine/runners/phantom.rb in phantom_jasmine-0.0.7
- old
+ new
@@ -1,16 +1,18 @@
require 'facter'
+require 'jasmine'
require 'tempfile'
-require 'phantomjs-mac' if RUBY_PLATFORM.downcase.include?('darwin')
+require 'phantomjs.rb'
class Jasmine::Runners::Phantom
attr_accessor :suites
def initialize(port, results_processor, result_batch_size)
@port = port
@results_processor = results_processor
@result_batch_size = result_batch_size
+ @phantom = Phantomjs.send(:get_executable)
end
def run
load_suite_info
@results_processor.process(results_hash, suites)
@@ -18,30 +20,29 @@
private
def load_suite_info
tmpfile = Tempfile.new('count')
- pid = Process.spawn "#{Phantomjs.executable_path} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_count.js')}' #{@port}", :out => tmpfile.path
+ pid = Process.spawn "#{@phantom} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_count.js')}' #{@port}", :out => tmpfile.path
Process.wait pid
json = JSON.parse(tmpfile.read, :max_nesting => 100).tap { tmpfile.close }
@suites = json['suites']
@top_level_suites = json['top_level_suites']
end
def run_suites(suites)
tmpfile = Tempfile.new('run')
commands = suites.map do |suite|
- "#{Phantomjs.executable_path} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_run.js')}' #{@port} '#{suite['description']}'"
+ "#{@phantom} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_run.js')}' #{@port} '#{suite['description']}'"
end.join(';echo ,;')
pid = Process.spawn "echo [;#{commands};echo ]", :out => tmpfile.path
[pid, tmpfile]
end
def results_hash
spec_results = {}
-
@top_level_suites.group_by { |suite| suite['id'] % processor_count }.map { |(k, suites)| run_suites(suites) }.each do |pid, tmpfile|
Process.wait pid
JSON.parse(tmpfile.read).each do |result|
result.each do |spec_id, spec_result|
@@ -55,9 +56,9 @@
spec_results
end
def processor_count
@processor_count ||= begin
- ENV['JASMINE_PARALLEL_COUNT'] || [Facter.sp_number_processors.to_i, 4].min
+ ENV['JASMINE_PARALLEL_COUNT'] || Facter.processorcount
end.to_i
end
end