From 55f9eade6992a4e7fbe27f41866b728ec6509137 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 10 Oct 2024 08:14:56 +0100 Subject: [PATCH] Merge pull request #3117 from rspec/push_requires_into_config_as_required As each file is required in RSpec::Core::Configuration, push it onto `requires`. --- Changelog.md | 5 +++++ lib/rspec/core/configuration.rb | 6 ++++-- spec/rspec/core/configuration_spec.rb | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 08e681ad7..c9a178ff8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,11 @@ ### Development [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.13.1...3-13-maintenance) +Bug fixes: + +* `RSpec::Configuration#requires` will reflect files already required, whilst requiring + them. (Jon Rowe, #3117) + ### 3.13.1 / 2024-09-02 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.13.0...v3.13.1) diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 8928f93ab..c207b7a7c 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -1597,8 +1597,10 @@ def configure_example(example, example_hooks) def requires=(paths) directories = ['lib', default_path].select { |p| File.directory? p } RSpec::Core::RubyProject.add_to_load_path(*directories) - paths.each { |path| load_file_handling_errors(:require, path) } - @requires += paths + paths.each { |path| + load_file_handling_errors(:require, path) + @requires << path + } end # @private diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 165990f5a..0a806cc85 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -238,6 +238,16 @@ def absolute_path_to(dir) expect(config.requires).to eq ['a/path'] end + it 'stores required paths "per file"' do + allow(config).to receive(:require).with('a/path') + expect(config).to receive(:require).with('another/path') do + expect(config.requires).to eq ['a/path'] + end + + config.requires = ['a/path', 'another/path'] + expect(config.requires).to eq ['a/path', 'another/path'] + end + context "when `default_path` refers to a file rather than a directory" do it 'does not add it to the load path' do config.default_path = 'Rakefile'