【问题标题】:Rspec expect success messageRspec期望成功消息
【发布时间】:2018-11-28 16:13:43
【问题描述】:

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

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

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

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

>>Expect true to be true - Test passed

【问题讨论】:

  • it "expect true to be true" do ... 这就是你在 RSpec 中的做法,没有其他方法。
  • 所以如果一个“it”包含多个期望,您就不能记录每个期望的成功,只能记录整个“it”?
  • 检查一下,Single expectation test - 每个测试应该只做出一个断言。

标签: rspec rspec3


【解决方案1】:

唯一的方法 - 使用期望描述块 (it '...' do)。另外,根据Single expectation test - 每个测试应该只做出一个断言,尽量避免使用一些期望。仅当您检查 ONE 事物时,名称也应为 one。或者更好地在单独的块中添加上下文/描述块和一些断言。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多