better errors and flatten jasmine.yml keys, allowing for merged yaml sequences in config

This commit is contained in:
John Bintz 2011-08-10 13:11:05 -04:00
parent 88d1b7f1d2
commit dc5b8c026d
5 changed files with 60 additions and 24 deletions

View File

@ -123,7 +123,7 @@ module Jasmine
data = @options[:config].dup data = @options[:config].dup
[ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root| [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root|
if data[searches] if data[searches]
data[searches].collect do |search| data[searches].flatten.collect do |search|
path = search path = search
path = File.join(data[root], path) if data[root] path = File.join(data[root], path) if data[root]
found_files = Dir[path] - @files found_files = Dir[path] - @files

View File

@ -8,6 +8,8 @@ module Jasmine
class TestFailure < StandardError; end class TestFailure < StandardError; end
class ConsoleLogUsage < StandardError ; end class ConsoleLogUsage < StandardError ; end
class JasmineConfigNotFound < Errno::ENOENT ; end
end end
end end

View File

@ -46,6 +46,8 @@ module Jasmine
end end
def jasmine_config def jasmine_config
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
@jasmine_config ||= JASMINE_DEFAULTS.dup.merge(YAML.load_file(@options[:jasmine_config])) @jasmine_config ||= JASMINE_DEFAULTS.dup.merge(YAML.load_file(@options[:jasmine_config]))
end end

View File

@ -38,6 +38,19 @@ describe Jasmine::FilesList do
end end
end end
shared_examples_for :reading_data do
it 'should read the data from the jasmine.yml file and add the files' do
files_list.files.should == Jasmine::FilesList::DEFAULT_FILES + [
File.expand_path(first_file),
File.expand_path(src_file),
File.expand_path(stylesheet_file),
File.expand_path(helper_file),
File.expand_path(spec_file)
]
end
end
context 'with normal list' do
let(:config) { { let(:config) { {
'src_dir' => src_dir, 'src_dir' => src_dir,
'spec_dir' => spec_dir, 'spec_dir' => spec_dir,
@ -47,14 +60,20 @@ describe Jasmine::FilesList do
'stylesheets' => [ 'stylesheet/*.css' ] 'stylesheets' => [ 'stylesheet/*.css' ]
} } } }
it 'should read the data from the jasmine.yml file and add the files' do it_should_behave_like :reading_data
files_list.files.should == Jasmine::FilesList::DEFAULT_FILES + [ end
File.expand_path(first_file),
File.expand_path(src_file), context 'with multidimensional list' do
File.expand_path(stylesheet_file), let(:config) { {
File.expand_path(helper_file), 'src_dir' => src_dir,
File.expand_path(spec_file) 'spec_dir' => spec_dir,
] 'src_files' => [ [ 'js/first_file.js', 'js/*.js' ] ],
'spec_files' => [ '*_spec.js' ],
'helpers' => [ 'helper/*.js' ],
'stylesheets' => [ 'stylesheet/*.css' ]
} }
it_should_behave_like :reading_data
end end
end end

View File

@ -18,11 +18,17 @@ describe Jasmine::Headless::Runner do
describe '#load_config' do describe '#load_config' do
include FakeFS::SpecHelpers include FakeFS::SpecHelpers
let(:opts) { { :jasmine_config => 'test.yml' } } before do
File.open('ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner', 'w')
end
let(:config_filename) { 'test.yml' }
let(:opts) { { :jasmine_config => config_filename } }
context 'file exists' do
before do before do
File.open(Jasmine::Headless::Runner::RUNNER, 'w') File.open(Jasmine::Headless::Runner::RUNNER, 'w')
File.open('test.yml', 'w') { |fh| fh.print YAML.dump('test' => 'hello') } File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello') }
end end
it 'should load the jasmine config' do it 'should load the jasmine config' do
@ -31,6 +37,13 @@ describe Jasmine::Headless::Runner do
end end
end end
context 'file does not exist' do
it 'should raise an exception' do
expect { runner.jasmine_config }.to raise_error(Jasmine::Headless::JasmineConfigNotFound, /#{config_filename}/)
end
end
end
describe '#jasmine_command' do describe '#jasmine_command' do
let(:opts) { { let(:opts) { {
:colors => true, :colors => true,