【问题标题】:Modify "ExpectationNotMet" output in Rspec修改 Rspec 中的“ExpectationNotMet”输出
【发布时间】:2015-07-27 15:41:34
【问题描述】:

我正在使用 Ruby、Rspec 和 Cucumber 来运行测试。我有这样的事情:

expect(@response.code).to eql(200)

并且当参数不是200时,显示如下输出:

(compared using eql?)
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/accounts_steps.rb:159:in `/^I see an? '(accepted|created|ok)' (create|authorization|payment|confirmation) response$/' features/honduras/honduras-claro-bundle-postpay.feature:9:in 
Then I see an 'accepted' create response

我需要在这个输出中添加一些相关信息,所以我想对其进行修改。如果可能的话,我想为此异常修改内置匹配器。有人可以帮忙吗?

非常感谢。

【问题讨论】:

    标签: ruby rspec cucumber


    【解决方案1】:

    你可以使用customized message:

    expect(@response.code).to eql(200), "Expected to respond with 200 OK, but got #{@response.code}"
    

    但是 matcher eql 默认应该打印这样的消息:

       expected: 200
            got: 404
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2022-08-11
      • 2019-07-07
      相关资源
      最近更新 更多