113 lines
2.7 KiB
Ruby
Executable File
113 lines
2.7 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
gem_dir = File.expand_path('../..', __FILE__)
|
|
$:.unshift(File.join(gem_dir, 'lib'))
|
|
|
|
require 'yaml'
|
|
require 'fileutils'
|
|
require 'getoptlong'
|
|
|
|
require 'rubygems'
|
|
|
|
gem 'jasmine'
|
|
gem 'coffee-script-source'
|
|
|
|
require 'jasmine'
|
|
require 'coffee_script/source'
|
|
|
|
require 'jasmine/cli'
|
|
|
|
include Jasmine::CLI
|
|
|
|
opts = GetoptLong.new(
|
|
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
|
|
[ '--no-colors', GetoptLong::NO_ARGUMENT ]
|
|
)
|
|
|
|
options = { :colors => false }
|
|
|
|
process_options = lambda { |*args|
|
|
opt = args.shift
|
|
case opt
|
|
when '--colors', '-c'
|
|
options[:colors] = true
|
|
when '--no-colors', '-nc'
|
|
options[:colors] = false
|
|
end
|
|
}
|
|
|
|
if File.file?('.jasmine-headless-webkit')
|
|
File.readlines('.jasmine-headless-webkit').collect { |line| line.strip.split(' ', 2) }.flatten(1).each(&process_options)
|
|
end
|
|
|
|
opts.each(&process_options)
|
|
|
|
data = YAML.load_file(ARGV.shift || 'spec/javascripts/support/jasmine.yml')
|
|
|
|
if !File.file?(File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'))
|
|
puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
|
|
exit 1
|
|
end
|
|
|
|
puts "Running Jasmine specs..."
|
|
|
|
files = [
|
|
'file://' + File.join(Jasmine.root, 'lib/jasmine.js'),
|
|
'file://' + File.join(Jasmine.root, 'lib/jasmine-html.js'),
|
|
'file://' + CoffeeScript::Source.bundled_path,
|
|
]
|
|
|
|
files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root|
|
|
data[searches] ||= DEFAULTS[searches]
|
|
data[root] ||= DEFAULTS[root]
|
|
|
|
if data[searches]
|
|
data[searches].collect do |search|
|
|
path = search
|
|
path = File.join(data[root], path) if data[root]
|
|
Dir[path]
|
|
end
|
|
end
|
|
end
|
|
|
|
files = files.flatten.compact.collect { |file|
|
|
case File.extname(file)
|
|
when '.js'
|
|
%{<script type="text/javascript" src="#{file}"></script>}
|
|
when '.coffee'
|
|
%{<script type="text/coffeescript" src="#{file}"></script>}
|
|
when '.css'
|
|
%{<link rel="stylesheet" href="#{file}" type="text/css" />}
|
|
end
|
|
}
|
|
|
|
output = <<-HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
"http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Jasmine Test Runner</title>
|
|
<script type="text/javascript">
|
|
window.console = { log: function(data) { debug.log(JSON.stringify(data)); } };
|
|
</script>
|
|
#{files.join("\n")}
|
|
</head>
|
|
<body>
|
|
|
|
<script type="text/javascript">
|
|
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
|
|
jasmine.getEnv().execute();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
HTML
|
|
|
|
File.open(target = "specrunner.#{$$}.html", 'w') { |fh| fh.print output }
|
|
system %{#{File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner')} #{options[:colors] ? '-c' : ''} #{target}}
|
|
status = $?.exitstatus
|
|
FileUtils.rm_f target
|
|
|
|
exit status
|
|
|