diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index 53ab9cd..a0fb58f 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -182,7 +182,11 @@ module Jasmine::Headless def add_files(patterns, type, dirs) dirs.product(patterns).each do |search| - Dir[File.join(*search)].find_all { |file| file[extension_filter] }.each do |path| + files = Dir[File.join(*search)].find_all { |file| file[extension_filter] } + + files.sort! { |a, b| rand(3) - 1 } if type == 'spec_files' + + files.each do |path| add_path(path, type) if File.file?(path) end end diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb index 5087399..dcd9bfc 100644 --- a/spec/lib/jasmine/headless/files_list_spec.rb +++ b/spec/lib/jasmine/headless/files_list_spec.rb @@ -175,5 +175,29 @@ describe Jasmine::Headless::FilesList do it { should == [ file_one, file_two, file_four ] } end end + + describe '#add_files' do + no_default_files! + + let(:dir) { 'tmp' } + + before do + srand(100) + + FileUtils.mkdir_p dir + + 10.times do |index| + File.open(File.join(dir, "file-#{index}.js"), 'wb') + end + 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 + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6529b58..54f9d56 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,7 @@ require 'fakefs/spec_helpers' RSpec.configure do |c| c.mock_with :mocha - #c.backtrace_clean_patterns = [] + c.backtrace_clean_patterns = [] c.before(:each) do Jasmine::Headless::CacheableAction.enabled = false @@ -42,6 +42,12 @@ class FakeFS::File RealFile.fnmatch?(pattern, file) end end + + class Stat + def file? + File.file?(@file) + end + end end module RSpec::Matchers