106 lines
2.7 KiB
Ruby
Executable File
106 lines
2.7 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
|
|
gem_dir = File.expand_path('../..', __FILE__)
|
|
$:.unshift(File.join(gem_dir, 'lib'))
|
|
|
|
require 'yaml'
|
|
require 'fileutils'
|
|
require 'getoptlong'
|
|
|
|
require 'jasmine'
|
|
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 ],
|
|
[ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ]
|
|
)
|
|
|
|
options = {
|
|
:colors => false,
|
|
:remove_html_file => true,
|
|
:jasmine_config => 'spec/javascripts/support/jasmine.yml'
|
|
}
|
|
|
|
@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', '-k'
|
|
options[:remove_html_file] = false
|
|
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 %{#{File.join(gem_dir, RUNNER)} #{options[:colors] ? '-c' : ''} #{target}}
|
|
status = $?.exitstatus
|
|
FileUtils.rm_f target if options[:remove_html_file] || (status == 0)
|
|
|
|
exit status
|
|
|