Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经看到这两种风格都被广泛使用:#1lambda { raise "Boom" }.should raise_error和 #2 expect { raise "Boom" }.to raise_error。我更喜欢expect..to,因为它读起来更好并且隐藏了proc的创建。
lambda { raise "Boom" }.should raise_error
expect { raise "Boom" }.to raise_error
我查看了 rspec 代码,似乎建议使用 expect..to,但是我经常遇到使用 lambda..should 的库。期望..更新,因此还没有“出名”吗?
expect从 rspec-2 开始使用,以前lambda必须使用。
expect
lambda
RSpec“官方”推荐使用expect并且他们可能会决定“废弃” lambda 语法。
在 RSpec1 时代开始使用的大多数库中都使用了 lambda 语法。他们只是还没有迁移(如果仍然受支持,他们为什么要迁移)。
因此,请使用expect而不是lambda.
.......[内容]