How to avoid deprecation warning for stub_chain in RSpec 3.0?

rspec, ruby-on-rails

Solution

RSpec.configure do |config|
  config.mock_with :rspec do |c|
    c.syntax = [:should, :expect]
  end
end

Notice that it's setting the rspec-mocks syntax, not the rspec-expectations syntax, as Paul's answer shows.

Problem

When I run a test with stub_chain, I'll get a deprecation warning. ``` describe "stubbing a chain of methods" do subject { Object.new } context "given symbols representing methods" do it "returns the correct value" do subject.stub_chain(:one, :two, :three).and_return(:four) expect(subject.one.two.three).to eq(:four) end end end ``` Deprecation Warnings: Using `stub_chain` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. How this warning can be avoided?

Original source