randomize spec load order because why not

This commit is contained in:
John Bintz 2011-11-25 18:11:21 -05:00
parent 16f867af09
commit f8db052281
3 changed files with 36 additions and 2 deletions

View File

@ -182,7 +182,11 @@ module Jasmine::Headless
def add_files(patterns, type, dirs) def add_files(patterns, type, dirs)
dirs.product(patterns).each do |search| 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) add_path(path, type) if File.file?(path)
end end
end end

View File

@ -175,5 +175,29 @@ describe Jasmine::Headless::FilesList do
it { should == [ file_one, file_two, file_four ] } it { should == [ file_one, file_two, file_four ] }
end end
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 end

View File

@ -8,7 +8,7 @@ require 'fakefs/spec_helpers'
RSpec.configure do |c| RSpec.configure do |c|
c.mock_with :mocha c.mock_with :mocha
#c.backtrace_clean_patterns = [] c.backtrace_clean_patterns = []
c.before(:each) do c.before(:each) do
Jasmine::Headless::CacheableAction.enabled = false Jasmine::Headless::CacheableAction.enabled = false
@ -42,6 +42,12 @@ class FakeFS::File
RealFile.fnmatch?(pattern, file) RealFile.fnmatch?(pattern, file)
end end
end end
class Stat
def file?
File.file?(@file)
end
end
end end
module RSpec::Matchers module RSpec::Matchers