Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 55f9ead

Browse files
committed
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`.
1 parent d092c00 commit 55f9ead

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
### Development
22
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.13.1...3-13-maintenance)
33

4+
Bug fixes:
5+
6+
* `RSpec::Configuration#requires` will reflect files already required, whilst requiring
7+
them. (Jon Rowe, #3117)
8+
49
### 3.13.1 / 2024-09-02
510
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.13.0...v3.13.1)
611

lib/rspec/core/configuration.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,8 +1597,10 @@ def configure_example(example, example_hooks)
15971597
def requires=(paths)
15981598
directories = ['lib', default_path].select { |p| File.directory? p }
15991599
RSpec::Core::RubyProject.add_to_load_path(*directories)
1600-
paths.each { |path| load_file_handling_errors(:require, path) }
1601-
@requires += paths
1600+
paths.each { |path|
1601+
load_file_handling_errors(:require, path)
1602+
@requires << path
1603+
}
16021604
end
16031605

16041606
# @private

spec/rspec/core/configuration_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,16 @@ def absolute_path_to(dir)
238238
expect(config.requires).to eq ['a/path']
239239
end
240240

241+
it 'stores required paths "per file"' do
242+
allow(config).to receive(:require).with('a/path')
243+
expect(config).to receive(:require).with('another/path') do
244+
expect(config.requires).to eq ['a/path']
245+
end
246+
247+
config.requires = ['a/path', 'another/path']
248+
expect(config.requires).to eq ['a/path', 'another/path']
249+
end
250+
241251
context "when `default_path` refers to a file rather than a directory" do
242252
it 'does not add it to the load path' do
243253
config.default_path = 'Rakefile'

0 commit comments

Comments
 (0)