class Jasmine::Runners::HTTP

Attributes

suites[RW]

Public Class Methods

new(client, results_processor, result_batch_size) click to toggle source
# File lib/jasmine/runners/http.rb, line 6
def initialize(client, results_processor, result_batch_size)
  @client = client
  @results_processor = results_processor
  @result_batch_size = result_batch_size
end

Public Instance Methods

run() click to toggle source
# File lib/jasmine/runners/http.rb, line 12
def run
  @client.connect
  load_suite_info
  wait_for_suites_to_finish_running
  results = @results_processor.process(results_hash, suites)
  @client.disconnect
  results
end

Private Instance Methods

eval_js(script) click to toggle source
# File lib/jasmine/runners/http.rb, line 61
def eval_js(script)
  @client.eval_js(script)
end
json_generate(obj) click to toggle source
# File lib/jasmine/runners/http.rb, line 65
def json_generate(obj)
  @client.json_generate(obj)
end
load_suite_info() click to toggle source
# File lib/jasmine/runners/http.rb, line 23
def load_suite_info
  started = Time.now
  while !eval_js('return jsApiReporter && jsApiReporter.started') do
    raise "couldn't connect to Jasmine after 60 seconds" if (started + 60 < Time.now)
    sleep 0.1
  end

  @suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }")
end
results_hash() click to toggle source
# File lib/jasmine/runners/http.rb, line 33
def results_hash
  spec_results = {}
  spec_ids.each_slice(@result_batch_size) do |slice|
    spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{json_generate(slice)}); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }"))
  end
  spec_results
end
spec_ids() click to toggle source
# File lib/jasmine/runners/http.rb, line 41
def spec_ids
  map_spec_ids = lambda do |suites|
    suites.map do |suite_or_spec|
      if suite_or_spec['type'] == 'spec'
        suite_or_spec['id']
      else
        map_spec_ids.call(suite_or_spec['children'])
      end
    end
  end
  map_spec_ids.call(@suites).compact.flatten
end
wait_for_suites_to_finish_running() click to toggle source
# File lib/jasmine/runners/http.rb, line 54
def wait_for_suites_to_finish_running
  puts "Waiting for suite to finish in browser ..."
  while !eval_js('return jsApiReporter.finished') do
    sleep 0.1
  end
end