jasmine-headless-webkit/bin/jasmine-headless-webkit
2011-05-12 17:02:11 -04:00

112 lines
2.8 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'
gem 'jasmine'
gem 'coffee-script'
gem 'rainbow'
require 'jasmine'
require 'coffee-script'
require 'rainbow'
require 'jasmine/cli'
include Jasmine::CLI
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_file if defaults_file?
opts.each(&@process_options)
@spec_filter = ARGV.dup
data = YAML.load_file(options[:jasmine_config])
if !File.file?(File.join(gem_dir, RUNNER))
puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
exit 1
end
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')
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]
files = Dir[path]
if searches == 'spec_files'
files = files.find_all { |file| use_spec?(file) }
end
files
end
end
end
files = files.flatten.compact.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.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