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

View File

@ -17,7 +17,10 @@ module Jasmine
:do_list => false,
:full_run => true,
:enable_cache => true,
:files => []
:files => [],
:reporters => [
[ 'HeadlessConsoleReporter' ]
]
}
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
@ -64,6 +67,10 @@ module Jasmine
@options[:do_list] = true
when '--seed'
@options[:seed] = arg.to_i
when '--format', '-f'
add_reporter(arg)
when '--out'
@options[:reporters].last << arg
end
end
@ -80,18 +87,47 @@ module Jasmine
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
[ '--no-colors', GetoptLong::NO_ARGUMENT ],
[ '--cache', GetoptLong::NO_ARGUMENT ],
[ '--no-t stcache', GetoptLong::NO_ARGUMENT ],
[ '--no-cache', GetoptLong::NO_ARGUMENT ],
[ '--keep', GetoptLong::NO_ARGUMENT ],
[ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ],
[ '--report', GetoptLong::REQUIRED_ARGUMENT ],
[ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ],
[ '--no-full-run', 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) }
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

View File

@ -4,6 +4,7 @@ require 'coffee-script'
require 'rainbow'
require 'yaml'
require 'erb'
require 'sprockets'
@ -112,7 +113,7 @@ module Jasmine
def jasmine_config_data
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

View File

@ -110,6 +110,45 @@ describe Jasmine::Headless::Options do
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
ARGV.replace(@argv)
end

View File

@ -37,13 +37,17 @@ describe Jasmine::Headless::Runner do
context 'file exists' do
before do
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
it 'should load the jasmine config' do
runner.jasmine_config['test'].should == 'hello'
runner.jasmine_config['spec_dir'].should == 'spec/javascripts'
end
it 'should execute ERB in the config file' do
runner.jasmine_config['erb'].should == 'erb'
end
end
context 'file does not exist' do