Class: Jasmine::Headless::TemplateWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/jasmine_headless_coverage_patches.rb

Instance Method Summary collapse

Instance Method Details

#old_writeObject



9
# File 'lib/tasks/jasmine_headless_coverage_patches.rb', line 9

alias old_write :write

#writeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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