Skip to content

Commit 561ecf7

Browse files
committed
experimental massacre
1 parent 48bee25 commit 561ecf7

File tree

5 files changed

+29
-53
lines changed

5 files changed

+29
-53
lines changed

spec/rspec/rails/example/controller_example_group_spec.rb

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,16 @@ def group_for(klass)
3131
# before #738 implicit subject definition for controllers caused
3232
# external methods to take precedence over our let definitions
3333

34-
with_isolated_config do |config|
35-
mod = Module.new do
36-
def my_helper
37-
"other_value"
38-
end
34+
mod = Module.new do
35+
def my_helper
36+
"other_value"
3937
end
40-
config.include mod
41-
group.class_exec do
42-
let(:my_helper) { "my_value" }
43-
end
44-
expect(group.new.my_helper).to eq "my_value"
4538
end
39+
config.include mod
40+
group.class_exec do
41+
let(:my_helper) { "my_value" }
42+
end
43+
expect(group.new.my_helper).to eq "my_value"
4644
end
4745
end
4846

@@ -109,10 +107,8 @@ def my_helper
109107

110108
context "when infer_base_class_for_anonymous_controllers is true" do
111109
around(:example) do |ex|
112-
with_isolated_config do |config|
113-
config.infer_base_class_for_anonymous_controllers = true
114-
ex.run
115-
end
110+
RSpec.configuration.infer_base_class_for_anonymous_controllers = true
111+
ex.run
116112
end
117113

118114
it "infers the anonymous controller class" do
@@ -129,10 +125,8 @@ def my_helper
129125

130126
context "when infer_base_class_for_anonymous_controllers is false" do
131127
around(:example) do |ex|
132-
with_isolated_config do |config|
133-
config.infer_base_class_for_anonymous_controllers = false
134-
ex.run
135-
end
128+
RSpec.configuration.infer_base_class_for_anonymous_controllers = false
129+
ex.run
136130
end
137131

138132
it "sets the anonymous controller class to ApplicationController" do

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,17 @@ def _view; end # Stub method
248248
end
249249

250250
it 'is accessible to hooks', pending: pending_only_on_ruby_22_rails_52 do
251-
with_isolated_config do
252-
run_count = 0
253-
RSpec.configuration.before(:each, type: :view) do
254-
allow(view).to receive(:render) { :value }
255-
run_count += 1
256-
end
257-
group = RSpec::Core::ExampleGroup.describe 'a view', type: :view do
258-
specify { expect(true).to eq true }
259-
end
260-
group.run(failure_reporter)
261-
expect(failure_reporter.exceptions).to eq []
262-
expect(run_count).to eq 1
251+
run_count = 0
252+
RSpec.configuration.before(:each, type: :view) do
253+
allow(view).to receive(:render) { :value }
254+
run_count += 1
255+
end
256+
group = RSpec::Core::ExampleGroup.describe 'a view', type: :view do
257+
specify { expect(true).to eq true }
263258
end
259+
group.run(failure_reporter)
260+
expect(failure_reporter.exceptions).to eq []
261+
expect(run_count).to eq 1
264262
end
265263
end
266264

spec/spec_helper.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Application < ::Rails::Application
1515
I18n.enforce_available_locales = true
1616

1717
require 'rspec/support/spec'
18+
require 'rspec/core/sandbox'
1819
require 'rspec/rails'
1920
require 'ammeter/init'
2021

@@ -52,9 +53,11 @@ def self.run_all(reporter = nil)
5253
config.raise_on_warning = true
5354

5455
config.around(:example) do |example|
55-
real_world = RSpec.world
56-
RSpec.instance_variable_set(:@world, RSpec::Core::World.new)
57-
example.run
58-
RSpec.instance_variable_set(:@world, real_world)
56+
RSpec::Core::Sandbox.sandboxed do |config|
57+
RSpec::Rails.initialize_configuration(config)
58+
example.run
59+
end
5960
end
61+
62+
config.include RSpec::Rails::FeatureCheck
6063
end

spec/support/helpers.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

spec/support/shared_examples.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ def define_group_in(path, group_definition)
2727
end
2828
end
2929

30-
around(:example) do |ex|
31-
with_isolated_config(&ex)
32-
end
33-
3430
it "adds does not add `:type` metadata on inclusion" do
3531
mixin = self.mixin
3632
group = RSpec.describe { include mixin }

0 commit comments

Comments
 (0)