Module: JasmineRails::Runner

Defined in:
lib/jasmine_rails/runner.rb

Class Method Summary collapse

Class Method Details

.run(spec_filter = nil, reporters = 'console') ⇒ Object

Run the Jasmine testsuite via phantomjs CLI raises an exception if any errors are encountered while running the testsuite



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jasmine_rails/runner.rb', line 8

def run(spec_filter = nil, reporters = 'console')
  override_rails_config do
    require 'phantomjs' if JasmineRails.use_phantom_gem?
    require 'fileutils'

    prepend_offline_asset_paths_helper
    html = get_spec_runner(spec_filter, reporters)
    FileUtils.mkdir_p JasmineRails.tmp_dir
    runner_path = JasmineRails.tmp_dir.join('runner.html')
    asset_prefix = Rails.configuration.assets.prefix.gsub(/\A\//,'')
    File.open(runner_path, 'w') {|f| f << html.gsub("/#{asset_prefix}", "./#{asset_prefix}")}

    phantomjs_runner_path = File.join(File.dirname(__FILE__), '..', 'assets', 'javascripts', 'jasmine-runner.js')
    phantomjs_cmd = JasmineRails.use_phantom_gem? ? Phantomjs.path : 'phantomjs'
    phantomjs_opts = JasmineRails.phantom_options.map { |option| "#{option}" }.join(' ')
    run_cmd %{"#{phantomjs_cmd}" #{phantomjs_opts} "#{phantomjs_runner_path}" "file://#{runner_path.to_s}?root=#{Rails.root.to_s}&spec=#{spec_filter}"}
  end
end