113 lines
2.8 KiB
Ruby
Executable File
113 lines
2.8 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
|
|
def gem_dir
|
|
File.expand_path('../..', __FILE__)
|
|
end
|
|
|
|
$:.unshift(File.join(gem_dir, 'lib'))
|
|
|
|
require 'yaml'
|
|
require 'fileutils'
|
|
require 'getoptlong'
|
|
|
|
require 'jasmine/base'
|
|
require 'coffee-script'
|
|
require 'rainbow'
|
|
|
|
require 'jasmine/cli'
|
|
include Jasmine::CLI
|
|
|
|
if !File.file?(File.join(gem_dir, RUNNER))
|
|
puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
|
|
exit 1
|
|
end
|
|
|
|
opts = GetoptLong.new(
|
|
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
|
|
[ '--no-colors', GetoptLong::NO_ARGUMENT ],
|
|
[ '--keep', GetoptLong::NO_ARGUMENT ],
|
|
[ '--report', GetoptLong::REQUIRED_ARGUMENT ],
|
|
[ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ]
|
|
)
|
|
|
|
options = {
|
|
:colors => false,
|
|
:remove_html_file => true,
|
|
:jasmine_config => 'spec/javascripts/support/jasmine.yml',
|
|
:report => false
|
|
}
|
|
|
|
@process_options = lambda { |*args|
|
|
opt, arg = args.flatten[0..1]
|
|
|
|
case opt
|
|
when '--colors', '-c'
|
|
options[:colors] = true
|
|
when '--no-colors', '-nc'
|
|
options[:colors] = false
|
|
when '--keep'
|
|
options[:remove_html_file] = false
|
|
when '--report'
|
|
options[:report] = arg
|
|
when '--jasmine-config', '-j'
|
|
options[:jasmine_config] = arg
|
|
end
|
|
}
|
|
|
|
read_defaults_files!
|
|
opts.each(&@process_options)
|
|
@spec_filter = ARGV.dup
|
|
|
|
data = YAML.load_file(options[:jasmine_config])
|
|
|
|
puts "Running Jasmine specs..."
|
|
|
|
files = %w{jasmine jasmine-html}.collect { |name| File.join(Jasmine.root, "lib/#{name}.js") }
|
|
files << File.join(gem_dir, 'jasmine/jasmine.headless-reporter.js')
|
|
|
|
[ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root|
|
|
if data[searches] ||= DEFAULTS[searches]
|
|
data[root] ||= DEFAULTS[root]
|
|
|
|
data[searches].collect do |search|
|
|
path = search
|
|
path = File.join(data[root], path) if data[root]
|
|
found_files = Dir[path]
|
|
if searches == 'spec_files'
|
|
found_files = found_files.find_all { |file| use_spec?(file) }
|
|
end
|
|
files += found_files
|
|
end
|
|
end
|
|
end
|
|
|
|
files = files.collect { |file|
|
|
case File.extname(file)
|
|
when '.js'
|
|
%{<script type="text/javascript" src="#{file}"></script>}
|
|
when '.coffee'
|
|
begin
|
|
%{<script type="text/javascript">#{CoffeeScript.compile(fh = File.open(file))}</script>}
|
|
rescue CoffeeScript::CompilationError => e
|
|
puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), e.message.to_s.color(:white) ]
|
|
exit 1
|
|
ensure
|
|
fh.close
|
|
end
|
|
when '.css'
|
|
%{<link rel="stylesheet" href="#{file}" type="text/css" />}
|
|
end
|
|
}
|
|
|
|
output = jasmine_html_template(files)
|
|
|
|
File.open(target = "specrunner.#{$$}.html", 'w') { |fh| fh.print output }
|
|
system jasmine_command(options, target)
|
|
status = $?.exitstatus
|
|
FileUtils.rm_f target if options[:remove_html_file] || (status == 0)
|
|
|
|
exit status
|
|
|