diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 641a1cc78..aa43eea43 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -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 diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 19512f166..3e787ef6d 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -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'