From 142a0c974b77d19d9645b78401126349eed1f324 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 24 Jan 2012 14:38:10 -0500 Subject: [PATCH] make sure src_files can also be loaded from other asset paths, should fix problem found by @christiannelson --- features/bin/two_files_from_src_files.feature | 11 ++++++++ .../bin/following_files_loaded_in_order.rb | 10 +++++++ lib/jasmine/headless/files_list.rb | 26 ++++++++++++------- .../two_files_from_src_files/app/app-file.js | 0 .../two_files_from_src_files/app/app.js | 2 ++ .../two_files_from_src_files/jasmine.yml | 7 +++++ .../vendor/vendor-file.js | 0 .../two_files_from_src_files/vendor/vendor.js | 2 ++ 8 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 features/bin/two_files_from_src_files.feature create mode 100644 features/steps/then/bin/following_files_loaded_in_order.rb create mode 100644 spec/jasmine/two_files_from_src_files/app/app-file.js create mode 100644 spec/jasmine/two_files_from_src_files/app/app.js create mode 100644 spec/jasmine/two_files_from_src_files/jasmine.yml create mode 100644 spec/jasmine/two_files_from_src_files/vendor/vendor-file.js create mode 100644 spec/jasmine/two_files_from_src_files/vendor/vendor.js diff --git a/features/bin/two_files_from_src_files.feature b/features/bin/two_files_from_src_files.feature new file mode 100644 index 0000000..af7efab --- /dev/null +++ b/features/bin/two_files_from_src_files.feature @@ -0,0 +1,11 @@ +Feature: Two files from source files + Scenario: Files are ordered directly + Given I have a test suite + When I run `bin/jasmine-headless-webkit -j spec/jasmine/two_files_from_src_files/jasmine.yml -l` + Then the exit status should be 0 + And the following files should be loaded in order: + | vendor/vendor-file.js | + | vendor/vendor.js | + | app/app-file.js | + | app/app.js | + diff --git a/features/steps/then/bin/following_files_loaded_in_order.rb b/features/steps/then/bin/following_files_loaded_in_order.rb new file mode 100644 index 0000000..7370d8c --- /dev/null +++ b/features/steps/then/bin/following_files_loaded_in_order.rb @@ -0,0 +1,10 @@ +Then /^the following files should be loaded in order:$/ do |table| + files = table.raw.flatten + + @output.lines.collect(&:strip).each do |line| + files.shift if line[files.first] + end + + files.should be_empty +end + diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index eef115a..b8b4da4 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -227,13 +227,13 @@ module Jasmine::Headless end def add_files(patterns, type, dirs) - dirs.product(patterns).each do |search| - files = expanded_dir(File.join(*search)) + patterns.each do |pattern| + dirs.collect { |dir| expanded_dir(File.join(dir, pattern)) }.each do |files| + files.sort! { |a, b| Kernel.rand(3) - 1 } if type == 'spec_files' - files.sort! { |a, b| Kernel.rand(3) - 1 } if type == 'spec_files' - - files.each do |path| - add_path(path, type) + files.each do |path| + add_path(path, type) + end end end @@ -271,7 +271,7 @@ module Jasmine::Headless end def src_dir - @src_dir ||= config_dir_or_pwd('src_dir') + @src_dir ||= config_dir_or_pwd('src_dir') + asset_paths end def spec_dir @@ -279,7 +279,7 @@ module Jasmine::Headless end def asset_paths - @asset_paths ||= config_dir_or_pwd('asset_paths') + @asset_paths ||= config_dir('asset_paths') end def spec_file_searches @@ -287,9 +287,15 @@ module Jasmine::Headless end def config_dir_or_pwd(dir) - found_dir = (@options[:config] && @options[:config][dir]) || Dir.pwd + if (found = config_dir(dir)).empty? + found = [ Dir.pwd ] + end - [ found_dir ].flatten.collect { |dir| File.expand_path(dir) } + found + end + + def config_dir(dir) + [ @options[:config] && @options[:config][dir] ].flatten.compact.collect { |dir| File.expand_path(dir) } end def filter_for_requested_specs(files) diff --git a/spec/jasmine/two_files_from_src_files/app/app-file.js b/spec/jasmine/two_files_from_src_files/app/app-file.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/jasmine/two_files_from_src_files/app/app.js b/spec/jasmine/two_files_from_src_files/app/app.js new file mode 100644 index 0000000..a307af7 --- /dev/null +++ b/spec/jasmine/two_files_from_src_files/app/app.js @@ -0,0 +1,2 @@ +//= require app-file +// diff --git a/spec/jasmine/two_files_from_src_files/jasmine.yml b/spec/jasmine/two_files_from_src_files/jasmine.yml new file mode 100644 index 0000000..494c646 --- /dev/null +++ b/spec/jasmine/two_files_from_src_files/jasmine.yml @@ -0,0 +1,7 @@ +src_dir: spec/jasmine/two_files_from_src_files/app + +asset_paths: +- "spec/jasmine/two_files_from_src_files/vendor" + +src_files: [ 'vendor.js', 'app.js' ] + diff --git a/spec/jasmine/two_files_from_src_files/vendor/vendor-file.js b/spec/jasmine/two_files_from_src_files/vendor/vendor-file.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/jasmine/two_files_from_src_files/vendor/vendor.js b/spec/jasmine/two_files_from_src_files/vendor/vendor.js new file mode 100644 index 0000000..f37a207 --- /dev/null +++ b/spec/jasmine/two_files_from_src_files/vendor/vendor.js @@ -0,0 +1,2 @@ +//= require vendor-file +//