diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index ac3a151..0b4db1b 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -123,7 +123,7 @@ module Jasmine data = @options[:config].dup [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root| if data[searches] - data[searches].collect do |search| + data[searches].flatten.collect do |search| path = search path = File.join(data[root], path) if data[root] found_files = Dir[path] - @files diff --git a/lib/jasmine/headless/errors.rb b/lib/jasmine/headless/errors.rb index ef92b8a..ac3487b 100644 --- a/lib/jasmine/headless/errors.rb +++ b/lib/jasmine/headless/errors.rb @@ -8,6 +8,8 @@ module Jasmine class TestFailure < StandardError; end class ConsoleLogUsage < StandardError ; end + + class JasmineConfigNotFound < Errno::ENOENT ; end end end diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index e4757d7..f3e4343 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -46,6 +46,8 @@ module Jasmine end 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])) end diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb index 5f3630b..26cd34a 100644 --- a/spec/lib/jasmine/files_list_spec.rb +++ b/spec/lib/jasmine/files_list_spec.rb @@ -38,23 +38,42 @@ describe Jasmine::FilesList do end end - 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' ] - } } + 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 - 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) - ] + context 'with normal 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 + + 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 diff --git a/spec/lib/jasmine/headless/runner_spec.rb b/spec/lib/jasmine/headless/runner_spec.rb index c39b9a4..bdbdd14 100644 --- a/spec/lib/jasmine/headless/runner_spec.rb +++ b/spec/lib/jasmine/headless/runner_spec.rb @@ -18,16 +18,29 @@ describe Jasmine::Headless::Runner do describe '#load_config' do include FakeFS::SpecHelpers - let(:opts) { { :jasmine_config => 'test.yml' } } - before do - File.open(Jasmine::Headless::Runner::RUNNER, 'w') - File.open('test.yml', 'w') { |fh| fh.print YAML.dump('test' => 'hello') } + File.open('ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner', 'w') end - it 'should load the jasmine config' do - runner.jasmine_config['test'].should == 'hello' - runner.jasmine_config['spec_dir'].should == 'spec/javascripts' + let(:config_filename) { 'test.yml' } + let(:opts) { { :jasmine_config => config_filename } } + + 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