2011-06-16 13:51:49 +00:00
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
require 'coffee-script'
|
|
|
|
require 'rainbow'
|
|
|
|
|
2011-07-20 22:27:20 +00:00
|
|
|
require 'yaml'
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
module Jasmine
|
|
|
|
module Headless
|
|
|
|
class Runner
|
|
|
|
JASMINE_DEFAULTS = {
|
|
|
|
'spec_files' => [ '**/*[sS]pec.js' ],
|
|
|
|
'helpers' => [ 'helpers/**/*.js' ],
|
|
|
|
'spec_dir' => 'spec/javascripts',
|
|
|
|
'src_dir' => nil,
|
|
|
|
'stylesheets' => [],
|
2011-09-12 19:12:58 +00:00
|
|
|
'src_files' => [],
|
|
|
|
'backtrace' => []
|
2011-06-16 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 20:23:29 +00:00
|
|
|
RUNNER_DIR = File.expand_path('../../../../ext/jasmine-webkit-specrunner', __FILE__)
|
|
|
|
RUNNER = File.join(RUNNER_DIR, 'jasmine-webkit-specrunner')
|
2011-06-16 13:51:49 +00:00
|
|
|
|
2011-06-16 14:11:37 +00:00
|
|
|
attr_reader :options
|
|
|
|
|
|
|
|
def self.run(options = {})
|
|
|
|
options = Options.new(options) if !options.kind_of?(Options)
|
2011-06-16 13:51:49 +00:00
|
|
|
new(options).run
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options)
|
2011-07-14 20:23:29 +00:00
|
|
|
if !File.file?(RUNNER)
|
|
|
|
$stderr.puts "No runner found, attempting to compile..."
|
|
|
|
Dir.chdir RUNNER_DIR do
|
|
|
|
system %{ruby extconf.rb}
|
|
|
|
end
|
|
|
|
raise NoRunnerError if !File.file?(RUNNER)
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
2011-10-10 18:11:13 +00:00
|
|
|
def template_writer
|
|
|
|
@template_writer ||= TemplateWriter.new(self)
|
|
|
|
end
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
def jasmine_config
|
2011-08-10 17:11:05 +00:00
|
|
|
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
@jasmine_config ||= JASMINE_DEFAULTS.dup.merge(YAML.load_file(@options[:jasmine_config]))
|
|
|
|
end
|
|
|
|
|
|
|
|
def jasmine_command(*targets)
|
|
|
|
[
|
|
|
|
RUNNER,
|
|
|
|
@options[:colors] ? '-c' : nil,
|
|
|
|
@options[:report] ? "-r #{@options[:report]}" : nil,
|
|
|
|
*targets
|
|
|
|
].compact.join(" ")
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2011-09-01 14:39:29 +00:00
|
|
|
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
2011-09-01 13:38:53 +00:00
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
files_list = Jasmine::FilesList.new(
|
|
|
|
:config => jasmine_config,
|
|
|
|
:only => @options[:files]
|
|
|
|
)
|
|
|
|
|
2011-10-10 18:11:13 +00:00
|
|
|
targets = template_writer.write!(files_list)
|
2011-06-16 13:51:49 +00:00
|
|
|
run_targets = targets.dup
|
2011-06-23 13:29:07 +00:00
|
|
|
run_targets.pop if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope?
|
2011-06-16 13:51:49 +00:00
|
|
|
|
|
|
|
system jasmine_command(run_targets)
|
|
|
|
status = $?.exitstatus
|
|
|
|
|
2011-10-10 18:11:13 +00:00
|
|
|
if !(runner_filename || (@options[:remove_html_file] && status != 0))
|
2011-06-16 13:51:49 +00:00
|
|
|
targets.each { |target| FileUtils.rm_f target }
|
|
|
|
end
|
|
|
|
|
|
|
|
status
|
|
|
|
end
|
2011-10-10 18:11:13 +00:00
|
|
|
|
|
|
|
def runner_filename
|
|
|
|
options[:runner_output_filename]
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|