class JasmineCoverage

Tilt template to generate coverage instrumented Jasmine specs files.

Public Class Methods

app_asset_path() click to toggle source

Get the absolute path to the projects assets path `/app/assets`.

@return [String] the path to the Rails assets

@private

# File lib/guard/jasmine/coverage.rb, line 42
def self.app_asset_path
  @app_asset_path ||= File.join(Rails.root, 'app', 'assets')
end
coverage_bin() click to toggle source

Returns the coverage executable path.

@return [String] the path

@private

# File lib/guard/jasmine/coverage.rb, line 51
def self.coverage_bin
  @coverage_bin ||= which 'istanbul'
end

Public Instance Methods

evaluate(_context, _locals) click to toggle source

Returns a coverage instrumented JavaScript file

# File lib/guard/jasmine/coverage.rb, line 18
def evaluate(_context, _locals)
  return data if !ENV['IGNORE_INSTRUMENTATION'].to_s.empty? && file =~ Regexp.new(ENV['IGNORE_INSTRUMENTATION'])
  return data unless JasmineCoverage.coverage_bin
  return data unless file.include?(JasmineCoverage.app_asset_path)

  Dir.mktmpdir do |path|
    filename = File.basename(file)
    input    = File.join(path, filename).sub(/\.js.+/, '.js')

    File.write input, data

    result = `#{JasmineCoverage.coverage_bin} instrument --embed-source #{input.shellescape}`

    raise "Could not generate coverage instrumented file for #{file}" unless $CHILD_STATUS.exitstatus.zero?

    result.gsub input, file
  end
end
prepare() click to toggle source
# File lib/guard/jasmine/coverage.rb, line 13
def prepare
end