57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/simple_javascript_testing.rb', line 57
def run_javascript_test(html, template)
html.gsub! /<script src=\"#{AnyClass.prefix}([^\"]*)\"/ do |full|
if File.exists?(File.expand_path("public/assets/#{$1}"))
"<script src=\"#{File.expand_path("public/assets/#{$1}")}\""
elsif File.exists?(File.expand_path("vendor/assets/javascripts/#{$1}"))
"<script src=\"#{File.expand_path("vendor/assets/javascripts/#{$1}")}\""
else
full
end
end
html.gsub!("</head>", "<script src='#{File.expand_path('node_modules')}/simple_javascript_testing/lib/stub_ajax.js'></script></head>")
File.write("test/html/#{template}.html", html)
thing = "#{File.expand_path('html', AnyClass.test_directory)}/#{template}"
thing2 = "#{File.expand_path('javascript', AnyClass.test_directory)}/#{template}"
binary = if find_executable 'phantomjs'
"phantomjs"
else
"node_modules/simple_javascript_testing/node_modules/phantomjs/lib/phantom/bin/phantomjs"
end
result = system "#{binary} #{thing2}.js #{thing}.html"
if !result
raise "Javascript test failed"
end
end
|