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,23 +38,42 @@ describe Jasmine::FilesList do
end end
end end
let(:config) { { shared_examples_for :reading_data do
'src_dir' => src_dir, it 'should read the data from the jasmine.yml file and add the files' do
'spec_dir' => spec_dir, files_list.files.should == Jasmine::FilesList::DEFAULT_FILES + [
'src_files' => [ 'js/first_file.js', 'js/*.js' ], File.expand_path(first_file),
'spec_files' => [ '*_spec.js' ], File.expand_path(src_file),
'helpers' => [ 'helper/*.js' ], File.expand_path(stylesheet_file),
'stylesheets' => [ 'stylesheet/*.css' ] File.expand_path(helper_file),
} } File.expand_path(spec_file)
]
end
end
it 'should read the data from the jasmine.yml file and add the files' do context 'with normal list' do
files_list.files.should == Jasmine::FilesList::DEFAULT_FILES + [ let(:config) { {
File.expand_path(first_file), 'src_dir' => src_dir,
File.expand_path(src_file), 'spec_dir' => spec_dir,
File.expand_path(stylesheet_file), 'src_files' => [ 'js/first_file.js', 'js/*.js' ],
File.expand_path(helper_file), 'spec_files' => [ '*_spec.js' ],
File.expand_path(spec_file) 'helpers' => [ 'helper/*.js' ],
] 'stylesheets' => [ 'stylesheet/*.css' ]
} }
it_should_behave_like :reading_data
end
context 'with multidimensional list' do
let(:config) { {
'src_dir' => src_dir,
'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,16 +18,29 @@ 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 before do
File.open(Jasmine::Headless::Runner::RUNNER, 'w') File.open('ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner', 'w')
File.open('test.yml', 'w') { |fh| fh.print YAML.dump('test' => 'hello') }
end end
it 'should load the jasmine config' do let(:config_filename) { 'test.yml' }
runner.jasmine_config['test'].should == 'hello' let(:opts) { { :jasmine_config => config_filename } }
runner.jasmine_config['spec_dir'].should == 'spec/javascripts'
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') }
end
it 'should load the jasmine config' do
runner.jasmine_config['test'].should == 'hello'
runner.jasmine_config['spec_dir'].should == 'spec/javascripts'
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
end end