【问题标题】:Why does rspec 3 fail with error: only `receive_messages` matchers are supported?为什么 rspec 3 失败并出现错误:仅支持 `receive_messages` 匹配器?
【发布时间】:2023-03-15 06:15:02
【问题描述】:

我正在尝试将项目从 RSpec 2 升级到 RSpec 3,但失败并出现以下错误:

 Failure/Error: Unable to find matching line from backtrace
   only the `receive` or `receive_messages` matchers are supported with `expect(...).to`, but you have provided: #<RSpec::Matchers::BuiltIn::Equal:0x007f99a974a230>

下面是一行:

expect(last_response.ok?).to be true

This post suggests只需要一个

require 'rspec/expectations'
include RSpec::Matchers

但是,我已经这样做了,它仍然报告错误。 This user 似乎也遇到了这个问题,但截至 2015 年 3 月 30 日还没有找到解决方案。

我将 rspec 与 Sinatra 一起使用,不使用黄瓜或菠菜。

谁能解释如何解决 RSpec 3 中的这个错误?谢谢。

【问题讨论】:

  • 你确定你提到的那一行实际上是在给出错误吗?

标签: rspec rspec2 rspec3


【解决方案1】:

我已通过使用extend 而不是include 来纠正这个问题RSpec::Matchers。在调试这个并尝试集成 pry 时,我 found this post 建议进行更改。

因此,我的代码现在看起来像:

extend RSpec::Matchers

不是

include RSpec::Matchers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    相关资源
    最近更新 更多