Class: JasmineCoverage

Inherits:
Tilt::Template
  • Object
show all
Extended by:
Guard::Jasmine::Util
Defined in:
lib/guard/jasmine/coverage.rb

Overview

Tilt template to generate coverage instrumented Jasmine specs files.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Guard::Jasmine::Util

find_free_server_port, phantomjs_bin_valid?, runner_available?, which

Class Method Details

.app_asset_pathString

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

Returns:

  • (String)

    the path to the Rails assets



42
43
44
# File 'lib/guard/jasmine/coverage.rb', line 42

def self.app_asset_path
  @app_asset_path ||= File.join(Rails.root, 'app', 'assets')
end

.coverage_binString

Returns the coverage executable path.

Returns:

  • (String)

    the path



51
52
53
# File 'lib/guard/jasmine/coverage.rb', line 51

def self.coverage_bin
  @coverage_bin ||= which 'istanbul'
end

Instance Method Details

#evaluate(_context, _locals) ⇒ Object

Returns a coverage instrumented JavaScript file



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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

#prepareObject



13
14
# File 'lib/guard/jasmine/coverage.rb', line 13

def prepare
end