使用 Rspec Expect 而不是 should 的最佳方式

Best way to use Rspec Expect instead of should

我注意到我使用 should 而不是 expect rspec 收到折旧警告。我找不到为以下测试实现期望的最佳方法

it "is invalid without a goal" do 
  FactoryGirl.build(:project, goal: nil).should_not be_valid 
end 

如果有任何帮助或指引我正确的方向,将不胜感激。

根据 documentation 你可以使用 expect.to 如下:

it "is invalid without a goal" do 
   expect( FactoryGirl.build(:project, goal: nil) ).to_not be_valid 
end