ゼロモンキーパッチモード
RSpecによって行われるすべてのモンキーパッチを無効にするために、disable_monkey_patching! 設定オプションを使用します。
- DSLをグローバルに公開しないようにします。
 - rspec-expectationsの 
shouldおよびshould_not構文を無効にします。 - rspec-mocksの 
stub、should_receive、およびshould_not_receive構文を無効にします。 
RSpec.configure { |c| c.disable_monkey_patching! }
背景
以下の内容で "spec/example_describe_spec.rb" という名前のファイルがあるとします。
require 'spec_helper'
describe "specs here" do
  it "passes" do
  end
end
以下の内容で "spec/example_should_spec.rb" という名前のファイルがあるとします。
require 'spec_helper'
RSpec.describe "another specs here" do
  it "passes with monkey patched expectations" do
    x = 25
    x.should eq 25
    x.should_not be > 30
  end
  it "passes with monkey patched mocks" do
    x = double("thing")
    x.stub(:hello => [:world])
    x.should_receive(:count).and_return(4)
    x.should_not_receive(:all)
    (x.hello * x.count).should eq([:world, :world, :world, :world])
  end
end
以下の内容で "spec/example_expect_spec.rb" という名前のファイルがあるとします。
require 'spec_helper'
RSpec.describe "specs here too" do
  it "passes in zero monkey patching mode" do
    x = double("thing")
    allow(x).to receive(:hello).and_return([:world])
    expect(x).to receive(:count).and_return(4)
    expect(x).not_to receive(:all)
    expect(x.hello * x.count).to eq([:world, :world, :world, :world])
  end
  it "passes in zero monkey patching mode" do
    x = 25
    expect(x).to eq(25)
    expect(x).not_to be > 30
  end
end
デフォルトではRSpecはモンキーパッチを許可します
以下の内容で "spec/spec_helper.rb" という名前のファイルがあるとします。
# Empty spec_helper
rspec を実行すると、すべての例がパスするはずです。
disable_monkey_patching! でモンキーパッチされたメソッドは未  定義になります
以下の内容で "spec/spec_helper.rb" という名前のファイルがあるとします。
RSpec.configure do |config|
  config.disable_monkey_patching!
end
rspec spec/example_should_spec.rb を実行すると、出力には次のすべてが含まれるはずです。
| undefined method `should' | | unexpected message :stub |
rspec spec/example_describe_spec.rb を実行すると、出力には "undefined method `describe'" が含まれるはずです。
モンキーパッチなしで allow および expect 構文が機能します
以下の内容で "spec/spec_helper.rb" という名前のファイルがあるとします。
# Empty spec_helper