@@ -554,58 +554,51 @@ def loaded_files
554
554
end
555
555
end
556
556
557
- def specify_consistent_ordering_of_files_to_run
558
- allow ( File ) . to receive ( :directory? ) . and_call_original
559
- allow ( File ) . to receive ( :directory? ) . with ( 'a' ) { true }
560
- globbed_files = nil
561
- allow ( Dir ) . to receive ( :[] ) . with ( /^\{ ?a/ ) { globbed_files }
562
- allow ( Dir ) . to receive ( :[] ) . with ( a_string_starting_with ( Dir . getwd ) ) { [ ] }
563
-
564
- orderings = [
565
- %w[ a/1.rb a/2.rb a/3.rb ] ,
566
- %w[ a/2.rb a/1.rb a/3.rb ] ,
567
- %w[ a/3.rb a/2.rb a/1.rb ]
568
- ] . map do |files |
569
- globbed_files = files
570
- yield
571
- config . files_to_run
572
- end
557
+ it 'loads files in passed directories in alphabetical order to avoid OS-specific file-globbing non-determinism' do
558
+ define_dirs "spec/unit" => [
559
+ [ "spec/unit/b_spec.rb" , "spec/unit/a_spec.rb" ] ,
560
+ [ "spec/unit/a_spec.rb" , "spec/unit/b_spec.rb" ]
561
+ ]
573
562
574
- expect ( orderings . uniq . size ) . to eq ( 1 )
563
+ expect ( assign_files_or_directories_to_run "spec/unit" ) . to match [
564
+ file_at ( "spec/unit/a_spec.rb" ) ,
565
+ file_at ( "spec/unit/b_spec.rb" )
566
+ ]
567
+ expect ( assign_files_or_directories_to_run "spec/unit" ) . to match [
568
+ file_at ( "spec/unit/a_spec.rb" ) ,
569
+ file_at ( "spec/unit/b_spec.rb" )
570
+ ]
575
571
end
576
572
577
- context 'when the given directories match the pattern' do
578
- it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
579
- specify_consistent_ordering_of_files_to_run do
580
- config . pattern = 'a/*.rb'
581
- assign_files_or_directories_to_run 'a'
582
- end
583
- end
584
- end
573
+ it 'respects the user-specified order of files and directories passed at the command line' do
574
+ define_dirs "spec/b" => [ [ "spec/b/1_spec.rb" , "spec/b/2_spec.rb" ] ] ,
575
+ "spec/c" => [ [ "spec/c/1_spec.rb" , "spec/c/2_spec.rb" ] ]
585
576
586
- context 'when the pattern is given relative to the given directories' do
587
- it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
588
- specify_consistent_ordering_of_files_to_run do
589
- config . pattern = '*.rb'
590
- assign_files_or_directories_to_run 'a'
591
- end
592
- end
577
+ expect ( assign_files_or_directories_to_run "spec/b" , "spec/a1_spec.rb" , "spec/c" , "spec/a2_spec.rb" ) . to match [
578
+ file_at ( "spec/b/1_spec.rb" ) , file_at ( "spec/b/2_spec.rb" ) ,
579
+ file_at ( "spec/a1_spec.rb" ) ,
580
+ file_at ( "spec/c/1_spec.rb" ) , file_at ( "spec/c/2_spec.rb" ) ,
581
+ file_at ( "spec/a2_spec.rb" )
582
+ ]
593
583
end
594
584
595
- context 'when given multiple file paths' do
596
- it 'orders the files in a consistent ordering, regardless of the given order' do
597
- allow ( File ) . to receive ( :directory? ) { false } # fake it into thinking these a full file paths
598
-
599
- files = [ 'a/b/c_spec.rb' , 'c/b/a_spec.rb' ]
600
- assign_files_or_directories_to_run ( *files )
601
- ordering_1 = config . files_to_run
585
+ def define_dirs ( dirs_hash )
586
+ allow ( File ) . to receive ( :directory? ) do |path |
587
+ !path . end_with? ( ".rb" )
588
+ end
602
589
603
- assign_files_or_directories_to_run ( *files . reverse )
604
- ordering_2 = config . files_to_run
590
+ allow ( Dir ) . to receive ( :[] ) . and_return ( [ ] )
605
591
606
- expect ( ordering_1 ) . to eq ( ordering_2 )
592
+ dirs_hash . each do |dir , sequential_glob_return_values |
593
+ allow ( Dir ) . to receive ( :[] ) . with (
594
+ a_string_including ( dir , config . pattern )
595
+ ) . and_return ( *sequential_glob_return_values )
607
596
end
608
597
end
598
+
599
+ def file_at ( relative_path )
600
+ eq ( relative_path ) . or eq ( File . expand_path ( relative_path ) )
601
+ end
609
602
end
610
603
611
604
describe "#pattern" do
0 commit comments