当我 运行 测试 "rspec spec " 在控制台中时,我会收到弃用警告

When I run the test "rspec spec "In the console, I'll get a deprecation warning

describe Item do

  it 'calculates price according to a special formula' do
    item = Item.new('kettle', price: 200)
    item.price.should == 212
  end

end

弃用警告:

使用 rspec 中的 should-expectations 的旧 :should 语法而不明确启用该语法已被弃用。使用新的 :expect 语法或显式启用 :should config.expect_with(:rspec) { |c| c.syntax = :should } 代替。从 E:/work/storeapp/spec/item_spec.rb:9:in `block (2 levels) in '.

调用

如果您需要更多回溯以了解这些弃用中的任何一个 确定在哪里进行必要的更改,您可以配置 config.raise_errors_for_deprecations!,它会把 将弃用警告转化为错误,为您提供完整的回溯。

1 个弃用警告总数

在 0.00505 秒内完成(文件加载时间为 0.17058 秒) 1 个示例,0 次失败

如何避免此警告?

以新的风格编写测试:

expect(item.price).to eq 212

顺便说一句。看来你可能会做某事 risk/confusing。将 200 分配给该属性后,看到 getter 返回的同名另一个值将更加令人困惑。您是否考虑过单独保留原始方法并定义一个新方法(例如 price_with_vat)?