如何避免 RSpec 3.0 中 stub_chain 的弃用警告? [英] How to avoid deprecation warning for stub_chain in RSpec 3.0?
本文介绍了如何避免 RSpec 3.0 中 stub_chain 的弃用警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 stub_chain 运行测试时,我会收到弃用警告.
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
弃用警告:不推荐使用 rspec-mocks 的旧 :should
语法中的 stub_chain
而不显式启用该语法.改用新的 :expect
语法或显式启用 :should
.
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.
如何避免这种警告?
推荐答案
RSpec.configure do |config|
config.mock_with :rspec do |c|
c.syntax = [:should, :expect]
end
end
请注意,它设置的是 rspec-mocks 语法,而不是 rspec-expectations 语法,正如 Paul 的回答所示.
Notice that it's setting the rspec-mocks syntax, not the rspec-expectations syntax, as Paul's answer shows.
这篇关于如何避免 RSpec 3.0 中 stub_chain 的弃用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文