我正在尝试将项目从 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
这篇文章建议只需要
require 'rspec/expectations'
include RSpec::Matchers
但是,我已经这样做了,它仍然报告错误。该用户似乎也遇到了此问题,但截至 2015 年 3 月 30 日无法获得解决方案。
我用rspec和Sinatra,不使用黄瓜或菠菜。
谁能解释如何在RSpec 3中解决此错误?谢谢。
我已经通过使用extend
而不是include
来纠正这个问题 RSpec::Matchers
.在调试它并尝试集成 pry 时,我发现了这篇文章,它提出了更改。
因此,我的代码现在如下所示:
extend RSpec::Matchers
而不是
include RSpec::Matchers