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

Commit fcf9a77

Browse files
committed
Deal with circular dependency between world and config.
`RSpec::World#initialize` references `RSpec.configuration` and `RSpec::Configuration` references `RSpec.world` in a few places. This circular dependency is not ideal and has triggered infinite recursion during some recent changes I've tried to make. It would be nice to get rid of it entirely, but for now, this is the simplest change I can make it solve my immediate problems.
1 parent 3ada308 commit fcf9a77

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/rspec/core/configuration.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def treat_symbols_as_metadata_keys_with_true_values=(_value)
343343
# @private
344344
attr_writer :files_to_run
345345
# @private
346-
attr_accessor :filter_manager
346+
attr_accessor :filter_manager, :world
347347
# @private
348348
attr_accessor :static_config_filter_manager
349349
# @private
@@ -394,6 +394,7 @@ def initialize
394394
@derived_metadata_blocks = FilterableItemRepository::QueryOptimized.new(:any?)
395395
@threadsafe = true
396396
@max_displayed_failure_line_count = 10
397+
@world = World::Null
397398

398399
define_built_in_hooks
399400
end
@@ -1256,7 +1257,7 @@ def configure_group_with(group, module_list, application_method)
12561257

12571258
# @private
12581259
def configure_existing_groups(mod, meta, application_method)
1259-
RSpec.world.all_example_groups.each do |group|
1260+
world.all_example_groups.each do |group|
12601261
next unless meta.empty? || MetadataFilter.apply?(:any?, meta, group.metadata)
12611262
__send__(application_method, mod, group)
12621263
end
@@ -1352,7 +1353,7 @@ def load_spec_files
13521353
# in that case, the spec file was loaded by `ruby` and
13531354
# isn't loaded by us here so we only know about it because
13541355
# of an example group being registered in it.
1355-
RSpec.world.registered_example_group_files.each do |f|
1356+
world.registered_example_group_files.each do |f|
13561357
loaded_spec_files << f # the registered files are already expended absolute paths
13571358
end
13581359

@@ -1814,7 +1815,7 @@ def define_built_in_hooks
18141815
end
18151816

18161817
def assert_no_example_groups_defined(config_option)
1817-
return unless RSpec.world.example_groups.any?
1818+
return unless world.example_groups.any?
18181819

18191820
raise MustBeConfiguredBeforeExampleGroupsError.new(
18201821
"RSpec's #{config_option} configuration option must be configured before " \

lib/rspec/core/world.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class World
1212

1313
def initialize(configuration=RSpec.configuration)
1414
@configuration = configuration
15+
configuration.world = self
1516
@example_groups = []
1617
@example_group_counts_by_spec_file = Hash.new(0)
1718
@filtered_examples = Hash.new do |hash, group|
@@ -208,6 +209,14 @@ def fail_if_config_and_cli_options_invalid
208209
1 # exit code
209210
)
210211
end
212+
213+
# @private
214+
# Provides a null implementation for initial use by configuration.
215+
module Null
216+
def self.registered_example_group_files; []; end
217+
def self.example_groups; []; end
218+
def self.all_example_groups; []; end
219+
end
211220
end
212221
end
213222
end

spec/rspec/core/configuration_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module RSpec::Core
1010
let(:exclusion_filter) { config.exclusion_filter.rules }
1111
let(:inclusion_filter) { config.inclusion_filter.rules }
1212

13+
before { config.world = RSpec.world }
14+
1315
shared_examples_for "warning of deprecated `:example_group` during filtering configuration" do |method, *args|
1416
it "issues a deprecation warning when filtering by `:example_group`" do
1517
args << { :example_group => { :file_location => /spec\/unit/ } }

0 commit comments

Comments
 (0)