Created
January 12, 2015 02:41
-
-
Save BenMorganIO/f0d812cdf18a970d7851 to your computer and use it in GitHub Desktop.
Karma with Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| Tempfile.open("karma_unit.js", Rails.root.join("tmp")) do |f| | |
| f.write unit_js(application_spec_files) | |
| f.flush | |
| system "./node_modules/.bin/karma #{command} #{f.path} #{args}" | |
| end | |
| end | |
| def application_spec_files | |
| assets = Rails.application.assets | |
| assets.append_path Rails.root.join("spec/javascripts/support/karma") | |
| assets.find_asset("application_spec.js").to_a.map { |e| e.pathname.to_s } | |
| end | |
| def unit_js(files) | |
| unit_js = File.open("spec/javascripts/support/karma/config/unit.js", "r").read | |
| unit_js.gsub "APPLICATION_SPEC", "\"#{files.join("\",\n\"")}\"" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment