Skip to content

Commit 23383f1

Browse files
authored
Merge pull request #2420 from rspec/remove-monkey-patching
Stop using globally exposed DSL
2 parents ba869b2 + 088bd0a commit 23383f1

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

lib/rspec/rails/extensions/active_record/proxy.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
RSpec.configure do |rspec|
22
# Delay this in order to give users a chance to configure `expect_with`...
33
rspec.before(:suite) do
4-
if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations)
4+
if defined?(RSpec::Matchers) &&
5+
RSpec::Matchers.configuration.respond_to?(:syntax) && # RSpec 4 dropped support for monkey-patching `should` syntax
6+
RSpec::Matchers.configuration.syntax.include?(:should) &&
7+
defined?(ActiveRecord::Associations)
58
RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy
69
end
710
end

spec/spec_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def self.run_all(reporter = nil)
5555

5656
config.shared_context_metadata_behavior = :apply_to_host_groups
5757

58-
config.disable_monkey_patching!
58+
# Zero monkey patching mode is the default and only mode in RSpec 4
59+
config.disable_monkey_patching! if config.respond_to?(:disable_monkey_patching!)
5960

6061
config.warnings = true
6162
config.raise_on_warning = true

spec/support/generators.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def self.included(klass)
2020
klass.include(RSpec::Rails::FeatureCheck)
2121
end
2222

23-
shared_examples_for 'a model generator with fixtures' do |name, class_name|
23+
RSpec.shared_examples_for 'a model generator with fixtures' do |name, class_name|
2424
before { run_generator [name, '--fixture'] }
2525

2626
describe 'the spec' do
@@ -38,7 +38,7 @@ def self.included(klass)
3838
end
3939
end
4040

41-
shared_examples_for "a request spec generator" do
41+
RSpec.shared_examples_for "a request spec generator" do
4242
describe 'generated with flag `--no-request-specs`' do
4343
before do
4444
run_generator %w[posts --no-request-specs]

spec/support/shared_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'pathname'
22

3-
shared_examples_for "an rspec-rails example group mixin" do |type, *paths|
3+
RSpec.shared_examples_for "an rspec-rails example group mixin" do |type, *paths|
44
let(:mixin) { described_class }
55

66
def define_group_in(path, group_definition)

0 commit comments

Comments
 (0)