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

  testrigfolder = Jasmine::Coverage.output_dir+"/testrig"
  FileUtils.mkdir_p testrigfolder

  p "\nCopying all view files and potential javascript fixture folders so the JS has access to the html fixtures.\n"
  FileUtils.copy_entry("#{Jasmine::Coverage.output_dir}/../../spec", "#{testrigfolder}/spec")
  FileUtils.copy_entry("#{Jasmine::Coverage.output_dir}/../../app", "#{testrigfolder}/app")
  FileUtils.mkdir_p "#{testrigfolder}/target/fixtures"
  FileUtils.copy_entry("#{Jasmine::Coverage.output_dir}/../fixtures", "#{testrigfolder}/target/fixtures")
  FileUtils.mkdir_p "#{testrigfolder}/target/views"
  FileUtils.copy_entry("#{Jasmine::Coverage.output_dir}/../views", "#{testrigfolder}/target/views")

  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?("#{testrigfolder}/#{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 + "*******************************************************************\n\n"
      raise s
    end
    FileUtils.cp(s, testrigfolder)
  }

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

  puts "A copy of the complete page that was used as the test environment can be found here:"
  puts "#{outfile}"
  ret
end