Skip to content

Commit

Permalink
Merge pull request #2420 from rspec/remove-monkey-patching
Browse files Browse the repository at this point in the history
Stop using globally exposed DSL
  • Loading branch information
JonRowe committed Dec 26, 2020
1 parent e85c9d3 commit b6dbe51
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/rspec/rails/extensions/active_record/proxy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
RSpec.configure do |rspec|
# Delay this in order to give users a chance to configure `expect_with`...
rspec.before(:suite) do
if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations)
if defined?(RSpec::Matchers) &&
RSpec::Matchers.configuration.respond_to?(:syntax) && # RSpec 4 dropped support for monkey-patching `should` syntax
RSpec::Matchers.configuration.syntax.include?(:should) &&
defined?(ActiveRecord::Associations)
RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def self.run_all(reporter = nil)

config.shared_context_metadata_behavior = :apply_to_host_groups

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

config.warnings = true
config.raise_on_warning = true
Expand Down
4 changes: 2 additions & 2 deletions spec/support/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.included(klass)
klass.extend(Macros)
end

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

describe 'the spec' do
Expand All @@ -37,7 +37,7 @@ def self.included(klass)
end
end

shared_examples_for "a request spec generator" do
RSpec.shared_examples_for "a request spec generator" do
describe 'generated with flag `--no-request-specs`' do
before do
run_generator %w[posts --no-request-specs]
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pathname'

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

def define_group_in(path, group_definition)
Expand Down

0 comments on commit b6dbe51

Please sign in to comment.