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

Commit cb8a65e

Browse files
authored
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`.
2 parents 787670c + 739e435 commit cb8a65e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Enhancements:
77
allways print a line number rather than an example id when the line number is ambiguous.
88
(Baden Ashford, #3085)
99

10+
Bug fixes:
11+
12+
* `RSpec::Configuration#requires` will reflect files already required, whilst requiring
13+
them. (Jon Rowe, #3117)
14+
1015
### 3.13.1 / 2024-09-02
1116
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.13.0...v3.13.1)
1217

lib/rspec/core/configuration.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1604,8 +1604,10 @@ def configure_example(example, example_hooks)
16041604
def requires=(paths)
16051605
directories = ['lib', default_path].select { |p| File.directory? p }
16061606
RSpec::Core::RubyProject.add_to_load_path(*directories)
1607-
paths.each { |path| load_file_handling_errors(:require, path) }
1608-
@requires += paths
1607+
paths.each { |path|
1608+
load_file_handling_errors(:require, path)
1609+
@requires << path
1610+
}
16091611
end
16101612

16111613
# @private

spec/rspec/core/configuration_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ def absolute_path_to(dir)
237237
expect(config.requires).to eq ['a/path']
238238
end
239239

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

0 commit comments

Comments
 (0)