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

Commit

Permalink
As each file is required, push it onto requires
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Oct 10, 2024
1 parent 787670c commit 7cba761
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1604,8 +1604,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
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,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'
Expand Down

0 comments on commit 7cba761

Please sign in to comment.