Skip to content

Commit

Permalink
Ensure that each spec file is only loaded once.
Browse files Browse the repository at this point in the history
- Fixes rspec#546, in which trying to run 2 or more specific examples in the
  same file caused the whole file to be run. This was happening because
  the following command caused the file to be loaded twice, and the filter
  was not being applied to the second instance:

    rspec path/to/file:37 path/to/file:42
  • Loading branch information
dchelimsky committed Dec 30, 2011
1 parent 8ee5005 commit a97dab0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def configure_expectation_framework

# @private
def load_spec_files
files_to_run.map {|f| load File.expand_path(f) }
files_to_run.uniq.map {|f| load File.expand_path(f) }
raise_if_rspec_1_is_loaded
end

Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ module RSpec::Core
config.load_spec_files
end

it "loads each file once, even if duplicated in list" do
config.files_to_run = ["a_spec.rb", "a_spec.rb"]
config.should_receive(:load).once
config.load_spec_files
end

context "with rspec-1 loaded" do
before do
Object.const_set(:Spec, Module.new)
Expand Down
6 changes: 0 additions & 6 deletions spec/rspec/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@
describe RSpec::Core do

describe "#configuration" do

it "returns the same object every time" do
RSpec.configuration.should equal(RSpec.configuration)
end

end

describe "#configure" do

it "yields the current configuration" do
RSpec.configure do |config|
config.should eq(RSpec::configuration)
end
end

end

describe "#world" do

it "returns the RSpec::Core::World instance the current run is using" do
RSpec.world.should be_instance_of(RSpec::Core::World)
end

end

end

0 comments on commit a97dab0

Please sign in to comment.