class Jasmine::Headless::TemplateWriter

Public Instance Methods

old_write()
Alias for: write
write() click to toggle source
# File lib/tasks/jasmine_headless_coverage_patches.rb, line 11
def write
  ret = old_write
  str = File.open(all_tests_filename, "rb").read

  test_rigfolder = Jasmine::Coverage.output_dir+"/test-rig"
  FileUtils.mkdir_p test_rigfolder
  FileUtils.rm_rf(Dir.glob("#{test_rigfolder}/*")) # Clean out the old files

  p "Copying all view files and potential javascript fixture folders so the jasmine-coverage run has access to the html fixtures."
  copy_assets_to_test_dir(test_rigfolder, '../fixtures', 'target/fixtures')
  copy_assets_to_test_dir(test_rigfolder, '../views', 'target/views')
  # Here we must also copy the spec and app folders so that we have access to all the files if we need them for the test rig
  copy_assets_to_test_dir(test_rigfolder, '../../spec', 'spec')
  copy_assets_to_test_dir(test_rigfolder, '../../app', 'app')

  jss = str.scan(/<script type="text\/javascript" src="(.*)"><\/script>/)
  jss << str.scan(/<link rel="stylesheet" href="(.*)" type="text\/css" \/>/)
  jss << str.scan(/\.coffee\.js'\] = '(.*)';<\/script>/)
  jss.flatten!
  jss.each { |s|
    js = File.basename(s)
    str.sub!(s, js)
    if File.exists?("#{test_rigfolder}/#{js}") && js != 'index.js'
      s = "\n\n*****************************************************************************************************************\n"
      s = s + "Cannot copy file '#{js}' into jasmine coverage test rig folder.\n"
      s = s + "There is already another file of that name. You either have two files with the same name (but in different paths)\n"
      s = s + "or your filename is the same as that from a third party vendor.\n"
      s = s + "The problem stems from the fact that to run all js files from one folder (as is required by a serverless jasmine\n"
      s = s + "test), all your js files must have unique names, even if they are in different folders in your app hierarchy.\n"
      s = s + "*****************************************************************************************************************\n\n"
      raise s
    end
    FileUtils.cp(s, test_rigfolder)
  }

  outfile = "#{test_rigfolder}/jscoverage-test-rig.html"
  aFile = File.new(outfile, "w")
  aFile.write(str)
  aFile.close

  ret
end
Also aliased as: old_write

Private Instance Methods

copy_assets_to_test_dir(test_rigfolder, from_dir, to_dir) click to toggle source
# File lib/tasks/jasmine_headless_coverage_patches.rb, line 56
def copy_assets_to_test_dir(test_rigfolder, from_dir, to_dir)
  if File.exists? "#{Jasmine::Coverage.output_dir}/#{from_dir}"
    FileUtils.mkdir_p "#{test_rigfolder}/#{to_dir}"
    FileUtils.copy_entry("#{Jasmine::Coverage.output_dir}/#{from_dir}", "#{test_rigfolder}/#{to_dir}")
  end
end