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

Commit 4b4d28d

Browse files
committed
Remove 1.9 SystemStackError workaround
This basically reverts this commit 622a4b7 that works around a Ruby 1.9 bug http://bugs.ruby-lang.org/issues/3351 Also, it removes 'when user did not configure expectation framework' and 'when user did not configure mock framework' examples, since mock/expectation frameworks are immediately configured on World creation, and if user did not configure them, they both default to `:rspec`. No checks for defined example groups are necessary anymore.
1 parent eab14d0 commit 4b4d28d

File tree

3 files changed

+5
-127
lines changed

3 files changed

+5
-127
lines changed

lib/rspec/core/configuration.rb

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class Configuration
5454
Readers = Module.new
5555
include Readers
5656

57-
# @private
58-
class MustBeConfiguredBeforeExampleGroupsError < StandardError; end
59-
6057
# @private
6158
def self.define_reader(name)
6259
Readers.class_eval do
@@ -776,14 +773,6 @@ def mock_with(framework)
776773
RSpec::Core::MockingAdapters.const_get(const_name)
777774
end
778775

779-
new_name, old_name = [framework_module, @mock_framework].map do |mod|
780-
mod.respond_to?(:framework_name) ? mod.framework_name : :unnamed
781-
end
782-
783-
unless new_name == old_name
784-
assert_no_example_groups_defined(:mock_framework)
785-
end
786-
787776
if block_given?
788777
raise "#{framework_module} must respond to `configuration` so that " \
789778
"mock_with can yield it." unless framework_module.respond_to?(:configuration)
@@ -859,10 +848,6 @@ def expect_with(*frameworks)
859848
end
860849
end
861850

862-
if (modules - @expectation_frameworks).any?
863-
assert_no_example_groups_defined(:expect_with)
864-
end
865-
866851
if block_given?
867852
raise "expect_with only accepts a block with a single argument. " \
868853
"Call expect_with #{modules.length} times, " \
@@ -1615,6 +1600,9 @@ def load_spec_files
16151600
loaded_spec_files << file
16161601
end
16171602

1603+
configure_mock_framework
1604+
configure_expectation_framework
1605+
16181606
@spec_files_loaded = true
16191607
end
16201608

@@ -2243,15 +2231,6 @@ def define_built_in_hooks
22432231
end
22442232
end
22452233

2246-
def assert_no_example_groups_defined(config_option)
2247-
return unless world.example_groups.any?
2248-
2249-
raise MustBeConfiguredBeforeExampleGroupsError.new(
2250-
"RSpec's #{config_option} configuration option must be configured before " \
2251-
"any example groups are defined, but you have already defined a group."
2252-
)
2253-
end
2254-
22552234
def output_wrapper
22562235
@output_wrapper ||= OutputWrapper.new(output_stream)
22572236
end

lib/rspec/core/example_group.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,6 @@ def self.subclass(parent, description, args, registration_collection, &example_g
408408

409409
# @private
410410
def self.set_it_up(description, args, registration_collection, &example_group_block)
411-
# Ruby 1.9 has a bug that can lead to infinite recursion and a
412-
# SystemStackError if you include a module in a superclass after
413-
# including it in a subclass: https://gist.github.com/845896
414-
# To prevent this, we must include any modules in
415-
# RSpec::Core::ExampleGroup before users create example groups and have
416-
# a chance to include the same module in a subclass of
417-
# RSpec::Core::ExampleGroup. So we need to configure example groups
418-
# here.
419-
ensure_example_groups_are_configured
420-
421411
# Register the example with the group before creating the metadata hash.
422412
# This is necessary since creating the metadata hash triggers
423413
# `when_first_matching_example_defined` callbacks, in which users can
@@ -514,17 +504,6 @@ def self.top_level?
514504
superclass == ExampleGroup
515505
end
516506

517-
# @private
518-
def self.ensure_example_groups_are_configured
519-
unless defined?(@@example_groups_configured)
520-
RSpec.configuration.configure_mock_framework
521-
RSpec.configuration.configure_expectation_framework
522-
# rubocop:disable Style/ClassVars
523-
@@example_groups_configured = true
524-
# rubocop:enable Style/ClassVars
525-
end
526-
end
527-
528507
# @private
529508
def self.before_context_ivars
530509
@before_context_ivars ||= {}

spec/rspec/core/configuration_spec.rb

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -355,28 +355,10 @@ def mod.configuration; @config ||= Struct.new(:custom_setting).new; end
355355
context 'when there are already some example groups defined' do
356356
before { allow(RSpec::Support).to receive(:require_rspec_core) }
357357

358-
it 'raises an error since this setting must be applied before any groups are defined' do
358+
it 'does not raise an error' do
359359
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
360360
class_double("RSpec::Core::MockingAdapters::Mocha", :framework_name => :mocha).as_stubbed_const
361361

362-
expect {
363-
config.mock_with :mocha
364-
}.to raise_error(/must be configured before any example groups are defined/)
365-
end
366-
367-
it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
368-
config.mock_framework # called by RSpec when configuring the first example group
369-
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
370-
config.mock_with :rspec
371-
end
372-
373-
it 'does not raise an error if re-setting the same config' do
374-
class_double("RSpec::Core::MockingAdapters::Mocha", :framework_name => :mocha).as_stubbed_const
375-
376-
groups = []
377-
allow(RSpec.world).to receive_messages(:example_groups => groups)
378-
config.mock_with :mocha
379-
groups << double.as_null_object
380362
config.mock_with :mocha
381363
end
382364
end
@@ -487,26 +469,10 @@ def stub_expectation_adapters
487469
end
488470

489471
context 'when there are already some example groups defined' do
490-
it 'raises an error since this setting must be applied before any groups are defined' do
491-
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
492-
expect {
493-
config.expect_with :rspec
494-
}.to raise_error(/must be configured before any example groups are defined/)
495-
end
496-
497-
it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
498-
config.expectation_frameworks # called by RSpec when configuring the first example group
472+
it 'does not raise an error' do
499473
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
500474
config.expect_with :rspec
501475
end
502-
503-
it 'does not raise an error if re-setting the same config' do
504-
groups = []
505-
allow(RSpec.world).to receive_messages(:example_groups => groups)
506-
config.expect_with :minitest
507-
groups << double.as_null_object
508-
config.expect_with :minitest
509-
end
510476
end
511477
end
512478

@@ -2768,52 +2734,6 @@ def in_fully_monkey_patched_rspec_environment
27682734
}.to change { Marshal.respond_to?(:dump_with_rspec_mocks) }.from(true).to(false)
27692735
end
27702736
end
2771-
2772-
context 'when user did not configure mock framework' do
2773-
def emulate_not_configured_mock_framework
2774-
in_fully_monkey_patched_rspec_environment do
2775-
allow(config).to receive(:rspec_mocks_loaded?).and_return(false, true)
2776-
config.instance_variable_set :@mock_framework, nil
2777-
ExampleGroup.send :remove_class_variable, :@@example_groups_configured
2778-
2779-
yield
2780-
end
2781-
end
2782-
2783-
it 'disables monkey patching after example groups being configured' do
2784-
emulate_not_configured_mock_framework do
2785-
obj = Object.new
2786-
config.disable_monkey_patching!
2787-
2788-
expect {
2789-
ExampleGroup.ensure_example_groups_are_configured
2790-
}.to change { obj.respond_to?(:should_receive) }.from(true).to(false)
2791-
end
2792-
end
2793-
end
2794-
2795-
context 'when user did not configure expectation framework' do
2796-
def emulate_not_configured_expectation_framework
2797-
in_fully_monkey_patched_rspec_environment do
2798-
allow(config).to receive(:rspec_expectations_loaded?).and_return(false, true)
2799-
config.instance_variable_set :@expectation_frameworks, []
2800-
ExampleGroup.send :remove_class_variable, :@@example_groups_configured
2801-
2802-
yield
2803-
end
2804-
end
2805-
2806-
it 'disables monkey patching after example groups being configured' do
2807-
emulate_not_configured_expectation_framework do
2808-
obj = Object.new
2809-
config.disable_monkey_patching!
2810-
2811-
expect {
2812-
ExampleGroup.ensure_example_groups_are_configured
2813-
}.to change { obj.respond_to?(:should) }.from(true).to(false)
2814-
end
2815-
end
2816-
end
28172737
end
28182738

28192739
describe 'recording spec start time (for measuring load)' do

0 commit comments

Comments
 (0)