Why does rspec 3 fail with error: only `receive_messages` matchers are supported?

Why does rspec 3 fail with error: only `receive_messages` matchers are supported?

我正在尝试将项目从 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 中的这个错误吗?谢谢。

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

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

extend RSpec::Matchers

而不是

include RSpec::Matchers