Rspec 期待成功消息

Rspec expect success message

是否可以向预期结果添加成功消息? 我知道如何添加自定义错误消息

expect(true).to be(true), "Expect true to be true"

但我想在 expect 顺利时添加一条消息,例如:

expect(true).to be(true), "Expect true to be true"

>>Expect true to be true - Test passed

唯一的方法——使用期望描述块(it '...' do)。另外,根据 Single expectation test - 每个测试应该只做一个断言,尽量避免使用几个期望。只有当你检查一件事情时,所以名字也应该是一件。或者更好地添加 context/describe 块并在单独的块中添加一些断言。