This commit is contained in:
John Bintz 2011-12-29 09:38:24 -05:00
commit 09f4df94de
5 changed files with 90 additions and 13 deletions

View File

@ -47,16 +47,13 @@ module Jasmine::Headless
end end
end end
begin if ENV['JHW_ENV']
require 'bundler' begin
require 'bundler'
envs = [ :default ] Bundler.require(ENV['JHW_ENV'].to_sym)
%w{JHW_ENV RAILS_ENV RACK_ENV RAILS_GROUPS}.each do |env| rescue LoadError
envs << ENV[env].to_sym if ENV[env]
end end
Bundler.require(*envs)
rescue LoadError
end end
# ...and unregister ones we don't want/need # ...and unregister ones we don't want/need

View File

@ -17,7 +17,10 @@ module Jasmine
:do_list => false, :do_list => false,
:full_run => true, :full_run => true,
:enable_cache => true, :enable_cache => true,
:files => [] :files => [],
:reporters => [
[ 'HeadlessConsoleReporter' ]
]
} }
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
@ -64,6 +67,10 @@ module Jasmine
@options[:do_list] = true @options[:do_list] = true
when '--seed' when '--seed'
@options[:seed] = arg.to_i @options[:seed] = arg.to_i
when '--format', '-f'
add_reporter(arg)
when '--out'
@options[:reporters].last << arg
end end
end end
@ -80,18 +87,47 @@ module Jasmine
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ], [ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
[ '--no-colors', GetoptLong::NO_ARGUMENT ], [ '--no-colors', GetoptLong::NO_ARGUMENT ],
[ '--cache', GetoptLong::NO_ARGUMENT ], [ '--cache', GetoptLong::NO_ARGUMENT ],
[ '--no-t stcache', GetoptLong::NO_ARGUMENT ], [ '--no-cache', GetoptLong::NO_ARGUMENT ],
[ '--keep', GetoptLong::NO_ARGUMENT ], [ '--keep', GetoptLong::NO_ARGUMENT ],
[ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ], [ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ],
[ '--report', GetoptLong::REQUIRED_ARGUMENT ], [ '--report', GetoptLong::REQUIRED_ARGUMENT ],
[ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ], [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ],
[ '--no-full-run', GetoptLong::NO_ARGUMENT ], [ '--no-full-run', GetoptLong::NO_ARGUMENT ],
[ '--list', '-l', GetoptLong::NO_ARGUMENT ], [ '--list', '-l', GetoptLong::NO_ARGUMENT ],
[ '--seed', GetoptLong::REQUIRED_ARGUMENT ] [ '--seed', GetoptLong::REQUIRED_ARGUMENT ],
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
[ '--out', GetoptLong::REQUIRED_ARGUMENT ]
) )
command_line_args.each { |*args| process_option(*args) } command_line_args.each { |*args| process_option(*args) }
end end
def reporters
file_index = 0
@options[:reporters].collect do |reporter, file|
output = [ reporter ]
if file
output << "report:#{file_index}"
output << file
file_index += 1
else
output << "stdout"
end
output
end
end
private
def add_reporter(name)
if !@added_reporter
@options[:reporters] = []
@added_reporter = true
end
@options[:reporters] << [ name ]
end
end end
end end
end end

View File

@ -4,6 +4,7 @@ require 'coffee-script'
require 'rainbow' require 'rainbow'
require 'yaml' require 'yaml'
require 'erb'
require 'sprockets' require 'sprockets'
@ -112,7 +113,7 @@ module Jasmine
def jasmine_config_data def jasmine_config_data
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
YAML.load_file(@options[:jasmine_config]) YAML.load(ERB.new(File.read(@options[:jasmine_config])).result(binding))
end end
end end
end end

View File

@ -110,6 +110,45 @@ describe Jasmine::Headless::Options do
end end
end end
let(:test_reporter) { 'TestReporter' }
let(:file) { 'file' }
context 'no reporters' do
it 'should have the default reporter' do
options[:reporters].should == [ [ 'HeadlessConsoleReporter' ] ]
end
end
context 'one reporter' do
context 'stdout' do
before do
ARGV.replace([ "--format", test_reporter ])
end
it 'should have the new reporter on stdout' do
options[:reporters].should == [ [ test_reporter ] ]
options.reporters.should == [ [ test_reporter, 'stdout' ] ]
end
end
context 'file' do
before do
ARGV.replace([ "--format", test_reporter, '--out', file ])
end
it 'should have the new reporter on stdout' do
options[:reporters].should == [ [ test_reporter, file ] ]
options.reporters.should == [ [ test_reporter, 'report:0', file ] ]
end
end
end
context 'two reporters' do
end
after do after do
ARGV.replace(@argv) ARGV.replace(@argv)
end end

View File

@ -37,13 +37,17 @@ describe Jasmine::Headless::Runner do
context 'file exists' do context 'file exists' do
before do before do
File.open(Jasmine::Headless::Runner::RUNNER, 'w') File.open(Jasmine::Headless::Runner::RUNNER, 'w')
File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello') } File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello', 'erb' => '<%= "erb" %>') }
end end
it 'should load the jasmine config' do it 'should load the jasmine config' do
runner.jasmine_config['test'].should == 'hello' runner.jasmine_config['test'].should == 'hello'
runner.jasmine_config['spec_dir'].should == 'spec/javascripts' runner.jasmine_config['spec_dir'].should == 'spec/javascripts'
end end
it 'should execute ERB in the config file' do
runner.jasmine_config['erb'].should == 'erb'
end
end end
context 'file does not exist' do context 'file does not exist' do