@@ -412,6 +412,14 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])
412
412
end
413
413
end
414
414
415
+ context "defined in $XDG_CONFIG_HOME/rspec/options" do
416
+ it "mentions the file name in the error so users know where to look for it" do
417
+ file_name = File . expand_path ( "~/.config/rspec/options" )
418
+ create_fixture_file ( file_name , "--foo_bar" )
419
+ expect_parsing_to_fail_mentioning_source ( file_name )
420
+ end
421
+ end
422
+
415
423
context "defined in SPEC_OPTS" do
416
424
it "mentions ENV['SPEC_OPTS'] as the source in the error so users know where to look for it" do
417
425
with_env_vars 'SPEC_OPTS' => "--foo_bar" do
@@ -440,25 +448,43 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])
440
448
end
441
449
end
442
450
443
- describe "sources: ~/.rspec, ./.rspec, ./.rspec-local, custom, CLI, and SPEC_OPTS" do
444
- it "merges global, local, SPEC_OPTS, and CLI" do
445
- File . open ( "./.rspec" , "w" ) { |f | f << "--require some_file" }
446
- File . open ( "./.rspec-local" , "w" ) { |f | f << "--format global" }
447
- File . open ( File . expand_path ( "~/.rspec" ) , "w" ) { |f | f << "--force-color" }
451
+ describe "sources: $XDG_CONFIG_HOME/rspec/options, ~/.rspec, ./.rspec, ./.rspec-local, custom, CLI, and SPEC_OPTS" do
452
+ it "merges both global, local, SPEC_OPTS, and CLI" do
453
+ create_fixture_file ( "./.rspec" , "--require some_file" )
454
+ create_fixture_file ( "./.rspec-local" , "--format global" )
455
+ create_fixture_file ( "~/.rspec" , "--force-color" )
456
+ create_fixture_file ( "~/.config/rspec/options" , "--order defined" )
448
457
with_env_vars 'SPEC_OPTS' => "--example 'foo bar'" do
449
458
options = parse_options ( "--drb" )
450
459
expect ( options [ :color_mode ] ) . to eq ( :on )
451
460
expect ( options [ :requires ] ) . to eq ( [ "some_file" ] )
452
461
expect ( options [ :full_description ] ) . to eq ( [ /foo\ bar/ ] )
453
462
expect ( options [ :drb ] ) . to be_truthy
454
463
expect ( options [ :formatters ] ) . to eq ( [ [ 'global' ] ] )
464
+ expect ( options [ :order ] ) . to eq ( "defined" )
465
+ end
466
+ end
467
+
468
+ it "uses $XDG_CONFIG_HOME environment variable when set to find XDG global options" do
469
+ create_fixture_file ( "~/.config/rspec/options" , "--format default_xdg" )
470
+ create_fixture_file ( "~/.custom-config/rspec/options" , "--format overridden_xdg" )
471
+
472
+ with_env_vars 'XDG_CONFIG_HOME' => "~/.custom-config" do
473
+ options = parse_options ( )
474
+ expect ( options [ :formatters ] ) . to eq ( [ [ 'overridden_xdg' ] ] )
475
+ end
476
+
477
+ without_env_vars 'XDG_CONFIG_HOME' do
478
+ options = parse_options ( )
479
+ expect ( options [ :formatters ] ) . to eq ( [ [ 'default_xdg' ] ] )
455
480
end
456
481
end
457
482
458
483
it 'ignores file or dir names put in one of the option files or in SPEC_OPTS, since those are for persistent options' do
459
- File . open ( "./.rspec" , "w" ) { |f | f << "path/to/spec_1.rb" }
460
- File . open ( "./.rspec-local" , "w" ) { |f | f << "path/to/spec_2.rb" }
461
- File . open ( File . expand_path ( "~/.rspec" ) , "w" ) { |f | f << "path/to/spec_3.rb" }
484
+ create_fixture_file ( "./.rspec" , "path/to/spec_1.rb" )
485
+ create_fixture_file ( "./.rspec-local" , "path/to/spec_2.rb" )
486
+ create_fixture_file ( "~/.rspec" , "path/to/spec_3.rb" )
487
+ create_fixture_file ( "~/.config/rspec/options" , "path/to/spec_4.rb" )
462
488
with_env_vars 'SPEC_OPTS' => "path/to/spec_4.rb" do
463
489
options = parse_options ( )
464
490
expect ( options [ :files_or_directories_to_run ] ) . to eq ( [ ] )
@@ -472,13 +498,14 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])
472
498
end
473
499
474
500
it "prefers CLI over file options" do
475
- File . open ( "./.rspec" , "w" ) { |f | f << "--format project" }
476
- File . open ( File . expand_path ( "~/.rspec" ) , "w" ) { |f | f << "--format global" }
501
+ create_fixture_file ( "./.rspec" , "--format project" )
502
+ create_fixture_file ( "~/.rspec" , "--format global" )
503
+ create_fixture_file ( "~/.config/rspec/options" , "--format xdg" )
477
504
expect ( parse_options ( "--format" , "cli" ) [ :formatters ] ) . to eq ( [ [ 'cli' ] ] )
478
505
end
479
506
480
507
it "prefers CLI over file options for filter inclusion" do
481
- File . open ( "./.rspec" , "w" ) { | f | f << " --tag ~slow"}
508
+ create_fixture_file ( "./.rspec" , "--tag ~slow" )
482
509
opts = config_options_object ( "--tag" , "slow" )
483
510
config = RSpec ::Core ::Configuration . new
484
511
opts . configure ( config )
@@ -487,14 +514,15 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])
487
514
end
488
515
489
516
it "prefers project file options over global file options" do
490
- File . open ( "./.rspec" , "w" ) { |f | f << "--format project" }
491
- File . open ( File . expand_path ( "~/.rspec" ) , "w" ) { |f | f << "--format global" }
517
+ create_fixture_file ( "./.rspec" , "--format project" )
518
+ create_fixture_file ( "~/.rspec" , "--format global" )
519
+ create_fixture_file ( "~/.config/rspec/options" , "--format xdg" )
492
520
expect ( parse_options [ :formatters ] ) . to eq ( [ [ 'project' ] ] )
493
521
end
494
522
495
523
it "prefers local file options over project file options" do
496
- File . open ( "./.rspec-local" , "w" ) { | f | f << " --format local"}
497
- File . open ( "./.rspec" , "w" ) { | f | f << " --format global"}
524
+ create_fixture_file ( "./.rspec-local" , "--format local" )
525
+ create_fixture_file ( "./.rspec" , "--format global" )
498
526
expect ( parse_options [ :formatters ] ) . to eq ( [ [ 'local' ] ] )
499
527
end
500
528
@@ -510,16 +538,17 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])
510
538
511
539
context "with custom options file" do
512
540
it "ignores project and global options files" do
513
- File . open ( "./.rspec" , "w" ) { |f | f << "--format project" }
514
- File . open ( File . expand_path ( "~/.rspec" ) , "w" ) { |f | f << "--format global" }
515
- File . open ( "./custom.opts" , "w" ) { |f | f << "--force-color" }
541
+ create_fixture_file ( "./.rspec" , "--format project" )
542
+ create_fixture_file ( "~/.rspec" , "--format global" )
543
+ create_fixture_file ( "~/.config/rspec/options" , "--format xdg" )
544
+ create_fixture_file ( "./custom.opts" , "--force-color" )
516
545
options = parse_options ( "-O" , "./custom.opts" )
517
546
expect ( options [ :format ] ) . to be_nil
518
547
expect ( options [ :color_mode ] ) . to eq ( :on )
519
548
end
520
549
521
550
it "parses -e 'full spec description'" do
522
- File . open ( "./custom.opts" , "w" ) { | f | f << " -e 'The quick brown fox jumps over the lazy dog'"}
551
+ create_fixture_file ( "./custom.opts" , "-e 'The quick brown fox jumps over the lazy dog'" )
523
552
options = parse_options ( "-O" , "./custom.opts" )
524
553
expect ( options [ :full_description ] ) . to eq ( [ /The\ quick\ brown\ fox\ jumps\ over\ the\ lazy\ dog/ ] )
525
554
end
0 commit comments