38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/simple_javascript_testing.rb', line 38
def call_template_with_js(template, &block)
data = AnyClass.new
if block_given?
yield data
end
FileUtils.mkdir_p("test/html/#{File.dirname template}")
FileUtils.mkdir_p("test/javascript/#{File.dirname template}")
html = data.build_html(template)
html.gsub!("<head>", "<head><script src='#{File.expand_path('node_modules')}/simple_javascript_testing/lib/stub_ajax.js'></script>")
html.gsub!("<script src='#{AnyClass.prefix}", "<script src='#{File.expand_path('public')}")
File.write("test/html/#{template}.html", html)
thing = "#{File.expand_path('html', 'test')}/#{template}"
thing2 = "#{File.expand_path('javascript', 'test')}/#{template}"
binary = if find_executable 'phantomjs'
"phantomjs"
else
"node_modules/simple_javascript_testing/node_modules/phantomjs/lib/phantom/bin/phantomjs"
end
system "#{binary} #{thing2}.js #{thing}.html"
end
|