diff --git a/.gitignore b/.gitignore index f301dd4..54583c8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ jhw-test _site/ jhw.*.html coverage/ +tmp/ diff --git a/lib/jasmine/headless/file_checker.rb b/lib/jasmine/headless/file_checker.rb index 749f054..fd7a3a7 100644 --- a/lib/jasmine/headless/file_checker.rb +++ b/lib/jasmine/headless/file_checker.rb @@ -1,10 +1,21 @@ module Jasmine::Headless::FileChecker def bad_format?(file) return if file.nil? - ::Jasmine::Headless::EXCLUDED_FORMATS.any? {|format| file.include?(".#{format}") } + + ::Jasmine::Headless::EXCLUDED_FORMATS.any? do |format| + file[%r{\.#{format}(\.|$)}] + end end def alert_bad_format(file) puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ] end -end \ No newline at end of file + + def alert_if_bad_format?(file) + if result = bad_format?(file) + alert_bad_format(file) + end + + result + end +end diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index 1c8a069..27f54ab 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -6,8 +6,9 @@ require 'sprockets' require 'sprockets/engines' module Jasmine::Headless - class FilesList + include FileChecker + class << self def vendor_asset_paths return @vendor_asset_paths if @vendor_asset_paths @@ -40,7 +41,7 @@ module Jasmine::Headless # ...and unregister ones we don't want/need Sprockets.instance_eval do - EXCLUDED_FORMATS.each do |extension| + EXCLUDED_FORMATS.each do |extension| register_engine ".#{extension}", Jasmine::Headless::NilTemplate end @@ -54,6 +55,12 @@ module Jasmine::Headless def default_files %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html} end + + def extension_filter + extensions = (%w{.js .css} + Sprockets.engine_extensions) + + %r{(#{extensions.join('|')})$} + end end PLEASE_WAIT_IM_WORKING_TIME = 2 @@ -212,11 +219,17 @@ module Jasmine::Headless end def expanded_dir(path) - Dir[path].find_all { |file| file[extension_filter] }.collect { |file| File.expand_path(file) }.find_all { |path| File.file?(path) } + Dir[path].find_all { |file| + file[extension_filter] && !alert_if_bad_format?(file) + }.collect { + |file| File.expand_path(file) + }.find_all { + |path| File.file?(path) + } end def extension_filter - %r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$} + self.class.extension_filter end def add_path(path, type) diff --git a/spec/integration/sprockets_spec.rb b/spec/integration/sprockets_spec.rb index 19f8cd6..10751cb 100644 --- a/spec/integration/sprockets_spec.rb +++ b/spec/integration/sprockets_spec.rb @@ -9,11 +9,15 @@ describe 'sprockets' do 'vendor/assets/javascripts/jquery.js', 'templates/that.jst.ejs', 'templates/this.jst', + 'things/jquery.string.js', 'assets/things/required.js', 'assets/things/code.js', 'assets/things/subcode/more_code.js', 'spec_helper.js', 'spec/things/code_spec.js' ) + + files.lines.to_a.any? { |line| line['assets/jquery.string.js: unsupported format'] }.should be_false end end + diff --git a/spec/jasmine/with_sprockets_includes/assets/things/jquery.string.js b/spec/jasmine/with_sprockets_includes/assets/things/jquery.string.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/jasmine/with_sprockets_includes/assets/things/required.js b/spec/jasmine/with_sprockets_includes/assets/things/required.js index 18241c9..9e80f9e 100644 --- a/spec/jasmine/with_sprockets_includes/assets/things/required.js +++ b/spec/jasmine/with_sprockets_includes/assets/things/required.js @@ -1,2 +1,3 @@ //= require 'jquery' +//= require 'things/jquery.string' diff --git a/spec/lib/jasmine/headless/file_checker_spec.rb b/spec/lib/jasmine/headless/file_checker_spec.rb index 571a73d..0e14a11 100644 --- a/spec/lib/jasmine/headless/file_checker_spec.rb +++ b/spec/lib/jasmine/headless/file_checker_spec.rb @@ -2,21 +2,24 @@ require 'spec_helper' describe Jasmine::Headless::FileChecker do include FakeFS::SpecHelpers - + let(:test_class) do object = Object.new object.class.send(:include, Jasmine::Headless::FileChecker) object end - + context "bad_format?" do it "should return false wth correct format" do test_class.bad_format?('foobar.js').should be_false end + it "should return false wth wrong format" do test_class.bad_format?('foobar.js.erb').should be_true end - end - + it "should check for the whole extension" do + test_class.bad_format?('foobar.string.js').should be_false + end + end end diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb index 111e281..d4037b8 100644 --- a/spec/lib/jasmine/headless/files_list_spec.rb +++ b/spec/lib/jasmine/headless/files_list_spec.rb @@ -204,15 +204,23 @@ describe Jasmine::Headless::FilesList do 10.times do |index| File.open(File.join(dir, "file-#{index}.js"), 'wb') end + + File.open(File.join(dir, 'file.js.erb'), 'wb') + end + + before do + files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ]) end it 'should load spec files in a random order' do - files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ]) - files_list.files.collect { |name| name[%r{\d+}] }.should == %w{6 7 1 0 5 3 4 8 2 9} FileUtils.rm_rf dir end + + it 'should not load an excluded format' do + files_list.files.any? { |file| file['.erb'] }.should be_false + end end end