Sha256: c78893868dfd317f76d47761cf9ce73025010eb454afde294c178eee02c95499

Contents?: true

Size: 908 Bytes

Versions: 8

Compression:

Stored size: 908 Bytes

Contents

namespace :karma  do
  task :start => :environment do
    with_tmp_config :start
  end

  task :run => :environment do
    with_tmp_config :start, "--single-run"
  end

  private

  def with_tmp_config(command, args = nil)
    pass = false
    Tempfile.open('karma_unit.js', Rails.root.join('spec') ) do |f|
      f.write unit_js(application_spec_files)
      f.flush
      pass = system "karma #{command} #{f.path} #{args}"
    end
    exit(pass)
  end

  def application_spec_files
    sprockets = Rails.application.assets
    sprockets.append_path Rails.root.join("spec/karma")
    files = Rails.application.assets.find_asset("application_spec.js").to_a.select { |e| e.pathname.to_s.end_with?('.js', '.es6')}.map {|e| e.pathname.to_s }
  end

  def unit_js(files)
    unit_js = File.open('spec/karma/config/unit.js', 'r').read
    unit_js.gsub "APPLICATION_SPEC", "\"#{files.join("\",\n\"")}\""
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aleph_analytics-0.1.0 lib/tasks/karma.rake
aleph_analytics-0.0.6 lib/tasks/karma.rake
aleph_analytics-0.0.5 lib/tasks/karma.rake
aleph_analytics-0.0.4 lib/tasks/karma.rake
aleph_analytics-0.0.3 lib/tasks/karma.rake
aleph_analytics-0.0.2 lib/tasks/karma.rake
aleph_analytics-0.0.1.alpha lib/tasks/karma.rake
aleph_analytics-0.0.0.alpha lib/tasks/karma.rake