Skip to content

Commit

Permalink
Merge pull request rspec#2328 from TravisSpangle/master
Browse files Browse the repository at this point in the history
Fix for rspec#2312
  • Loading branch information
JonRowe committed Sep 19, 2016
2 parents 27eb11a + d426bec commit 0841ad7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rspec/core.rb
Expand Up @@ -56,6 +56,7 @@ class << self
# they use the runner multiple times within the same process. Users must deal
# themselves with re-configuration of RSpec before run.
def self.reset
RSpec::ExampleGroups.remove_all_constants
@world = nil
@configuration = nil
end
Expand Down
6 changes: 6 additions & 0 deletions lib/rspec/core/example_group.rb
Expand Up @@ -827,6 +827,12 @@ def self.constant_scope_for(group)
const_scope
end

def self.remove_all_constants
constants.each do |constant|
__send__(:remove_const, constant)
end
end

def self.base_name_for(group)
return "Anonymous" if group.description.empty?

Expand Down
1 change: 1 addition & 0 deletions lib/rspec/core/world.rb
Expand Up @@ -38,6 +38,7 @@ def ordered_example_groups
#
# Reset world to 'scratch' before running suite.
def reset
RSpec::ExampleGroups.remove_all_constants
example_groups.clear
@shared_example_group_registry = nil
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/core/world_spec.rb
Expand Up @@ -13,6 +13,14 @@ module RSpec::Core
world.reset
expect(world.example_groups).to be_empty
end

it 'removes the previously assigned example group constants' do
RSpec.describe "group"

expect {
RSpec.world.reset
}.to change(RSpec::ExampleGroups, :constants).to([])
end
end

describe "#example_groups" do
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/core_spec.rb
Expand Up @@ -124,6 +124,14 @@
expect(RSpec.configuration).not_to equal(config_before_reset)
expect(RSpec.world).not_to equal(world_before_reset)
end

it 'removes the previously assigned example group constants' do
RSpec.describe "group"

expect {
RSpec.world.reset
}.to change(RSpec::ExampleGroups, :constants).to([])
end
end

describe ".clear_examples" do
Expand Down

0 comments on commit 0841ad7

Please sign in to comment.