Skip to content

Get rid of the code poking around RSpec's internals #2365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions spec/rspec/rails/example/controller_example_group_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def group_for(klass)
# before #738 implicit subject definition for controllers caused # before #738 implicit subject definition for controllers caused
# external methods to take precedence over our let definitions # external methods to take precedence over our let definitions


with_isolated_config do |config|
mod = Module.new do mod = Module.new do
def my_helper def my_helper
"other_value" "other_value"
Expand All @@ -44,7 +43,6 @@ def my_helper
expect(group.new.my_helper).to eq "my_value" expect(group.new.my_helper).to eq "my_value"
end end
end end
end


context "with explicit subject" do context "with explicit subject" do
it "uses the specified subject instead of the controller" do it "uses the specified subject instead of the controller" do
Expand Down Expand Up @@ -109,11 +107,9 @@ def my_helper


context "when infer_base_class_for_anonymous_controllers is true" do context "when infer_base_class_for_anonymous_controllers is true" do
around(:example) do |ex| around(:example) do |ex|
with_isolated_config do |config| RSpec.configuration.infer_base_class_for_anonymous_controllers = true
config.infer_base_class_for_anonymous_controllers = true
ex.run ex.run
end end
end


it "infers the anonymous controller class" do it "infers the anonymous controller class" do
group.controller { } group.controller { }
Expand All @@ -129,11 +125,9 @@ def my_helper


context "when infer_base_class_for_anonymous_controllers is false" do context "when infer_base_class_for_anonymous_controllers is false" do
around(:example) do |ex| around(:example) do |ex|
with_isolated_config do |config| RSpec.configuration.infer_base_class_for_anonymous_controllers = false
config.infer_base_class_for_anonymous_controllers = false
ex.run ex.run
end end
end


it "sets the anonymous controller class to ApplicationController" do it "sets the anonymous controller class to ApplicationController" do
group.controller { } group.controller { }
Expand Down
2 changes: 0 additions & 2 deletions spec/rspec/rails/example/view_example_group_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ def _view; end # Stub method


# Regression test from rspec/rspec-rails#833 # Regression test from rspec/rspec-rails#833
it 'is accessible to configuration-level hooks', pending: pending_only_on_ruby_22_rails_52 do it 'is accessible to configuration-level hooks', pending: pending_only_on_ruby_22_rails_52 do
with_isolated_config do
run_count = 0 run_count = 0
RSpec.configuration.before(:each, type: :view) do RSpec.configuration.before(:each, type: :view) do
# `view` is provided from the view example type, and serves to # `view` is provided from the view example type, and serves to
Expand All @@ -265,7 +264,6 @@ def _view; end # Stub method
expect(run_count).to eq 1 expect(run_count).to eq 1
end end
end end
end


describe "#template" do describe "#template" do
let(:view_spec) do let(:view_spec) do
Expand Down
13 changes: 10 additions & 3 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def self.world=(world)
I18n.enforce_available_locales = true I18n.enforce_available_locales = true


require 'rspec/support/spec' require 'rspec/support/spec'
require 'rspec/core/sandbox'
require 'rspec/rails' require 'rspec/rails'
require 'ammeter/init' require 'ammeter/init'


Expand Down Expand Up @@ -59,10 +60,16 @@ def self.run_all(reporter = nil)
config.warnings = true config.warnings = true
config.raise_on_warning = true config.raise_on_warning = true


# Execute a provided block with RSpec global objects (configuration,
# world, current example) reset. This is used to test specs with RSpec.
config.around(:example) do |example| config.around(:example) do |example|
real_world = RSpec.world RSpec::Core::Sandbox.sandboxed do |sandbox_config|
RSpec.instance_variable_set(:@world, RSpec::Core::World.new) # If there is an example-within-an-example, we want to make sure the inner
# example does not get a reference to the outer example (the real spec) if
# it calls something like `pending`.
sandbox_config.before(:context) { RSpec.current_example = nil }
RSpec::Rails.initialize_configuration(sandbox_config)
example.run example.run
RSpec.instance_variable_set(:@world, real_world) end
end end
end end
1 change: 1 addition & 0 deletions spec/support/generators.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def setup_default_destination


def self.included(klass) def self.included(klass)
klass.extend(Macros) klass.extend(Macros)
klass.include(RSpec::Rails::FeatureCheck)
end end


shared_examples_for 'a model generator with fixtures' do |name, class_name| shared_examples_for 'a model generator with fixtures' do |name, class_name|
Expand Down
14 changes: 0 additions & 14 deletions spec/support/helpers.rb

This file was deleted.

4 changes: 0 additions & 4 deletions spec/support/shared_examples.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def define_group_in(path, group_definition)
end end
end end


around(:example) do |ex|
with_isolated_config(&ex)
end

it "adds does not add `:type` metadata on inclusion" do it "adds does not add `:type` metadata on inclusion" do
mixin = self.mixin mixin = self.mixin
group = RSpec.describe { include mixin } group = RSpec.describe { include mixin }
Expand Down