@@ -483,7 +483,7 @@ def stub_expectation_adapters
483
483
484
484
it 'attempts to load the provided file names' do
485
485
assign_files_or_directories_to_run "path/to/some/file.rb"
486
- expect ( config . files_to_run ) . to eq ( [ "path/to/some/file.rb" ] )
486
+ expect ( config . files_to_run ) . to contain_files ( "path/to/some/file.rb" )
487
487
end
488
488
489
489
it 'does not attempt to load a file at the `default_path`' do
@@ -554,58 +554,71 @@ 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
585
+ it 'deduplicates spec files that are listed individually and present in a passed dir' do
586
+ define_dirs "spec/unit" => [ [
587
+ "spec/unit/a_spec.rb" ,
588
+ "spec/unit/b_spec.rb" ,
589
+ "spec/unit/c_spec.rb"
590
+ ] ]
591
+
592
+ expect ( assign_files_or_directories_to_run "spec/unit/b_spec.rb" , "spec/unit" ) . to match [
593
+ file_at ( "spec/unit/b_spec.rb" ) ,
594
+ file_at ( "spec/unit/a_spec.rb" ) ,
595
+ file_at ( "spec/unit/c_spec.rb" )
596
+ ]
597
+
598
+ expect ( assign_files_or_directories_to_run "spec/unit" , "spec/unit/b_spec.rb" ) . to match [
599
+ file_at ( "spec/unit/a_spec.rb" ) ,
600
+ file_at ( "spec/unit/b_spec.rb" ) ,
601
+ file_at ( "spec/unit/c_spec.rb" )
602
+ ]
603
+ end
598
604
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
605
+ def define_dirs ( dirs_hash )
606
+ allow ( File ) . to receive ( :directory? ) do |path |
607
+ !path . end_with? ( ".rb" )
608
+ end
602
609
603
- assign_files_or_directories_to_run ( *files . reverse )
604
- ordering_2 = config . files_to_run
610
+ allow ( Dir ) . to receive ( :[] ) . and_return ( [ ] )
605
611
606
- expect ( ordering_1 ) . to eq ( ordering_2 )
612
+ dirs_hash . each do |dir , sequential_glob_return_values |
613
+ allow ( Dir ) . to receive ( :[] ) . with (
614
+ a_string_including ( dir , config . pattern )
615
+ ) . and_return ( *sequential_glob_return_values )
607
616
end
608
617
end
618
+
619
+ def file_at ( relative_path )
620
+ eq ( relative_path ) . or eq ( File . expand_path ( relative_path ) )
621
+ end
609
622
end
610
623
611
624
describe "#pattern" do
@@ -819,10 +832,10 @@ def specify_consistent_ordering_of_files_to_run
819
832
820
833
it "allows file names with brackets" do
821
834
assign_files_or_directories_to_run "./path/to/a_[1:2]spec.rb"
822
- expect ( config . files_to_run ) . to eq ( [ "./path/to/a_[1:2]spec.rb" ] )
835
+ expect ( config . files_to_run ) . to contain_files ( "./path/to/a_[1:2]spec.rb" )
823
836
824
837
assign_files_or_directories_to_run "./path/to/a_spec.rb[foo]"
825
- expect ( config . files_to_run ) . to eq ( [ "./path/to/a_spec.rb[foo]" ] )
838
+ expect ( config . files_to_run ) . to contain_files ( "./path/to/a_spec.rb[foo]" )
826
839
end
827
840
828
841
context "with an example id" do
0 commit comments