在 RSpec 中:我可以像在 xUnit 风格的测试框架中那样将消息附加到支票上吗?怎么办?
assert_equal value1, value2, 'something is wrong'
最佳答案
对于 RSpec 3+:
消息可以自定义为字符串或使用 proc(查看引用资料)。
expect(1).to eq(2), 'one is not two!'
Customized message RSpec tries to provide useful failure messages, but for cases in which you want more specific information, you can define your own message right in the example. This works for any matcher other than the operator matchers.
对于旧的 RSpec 版本
should
和 should_not
采用第二个参数 (message
) 覆盖匹配器的默认消息。
1.should be(2), 'one is not two!'
不过,默认消息通常非常有用。
关于ruby - 如何将消息附加到 RSpec 检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4183656/