Skip to content

Commit b6dbe51

Browse files
committed
Merge pull request #2420 from rspec/remove-monkey-patching
Stop using globally exposed DSL
1 parent e85c9d3 commit b6dbe51

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
@@ -54,7 +54,8 @@ def self.run_all(reporter = nil)
5454

5555
config.shared_context_metadata_behavior = :apply_to_host_groups
5656

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

5960
config.warnings = true
6061
config.raise_on_warning = true

spec/support/generators.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.included(klass)
1919
klass.extend(Macros)
2020
end
2121

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

2525
describe 'the spec' do
@@ -37,7 +37,7 @@ def self.included(klass)
3737
end
3838
end
3939

40-
shared_examples_for "a request spec generator" do
40+
RSpec.shared_examples_for "a request spec generator" do
4141
describe 'generated with flag `--no-request-specs`' do
4242
before do
4343
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)