为什么rspec 3失败并出现错误:仅支持`receive_messages`匹配器?

时间:2015-03-30 23:48:09

标签: rspec rspec2 rspec3

我正在尝试将项目从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日还无法找到解决方案。

我正在使用Sinatra的rspec,不要使用黄瓜或菠菜。

任何人都可以解释如何在RSpec 3中解决此错误吗?感谢。

1 个答案:

答案 0 :(得分:4)

我已使用extend代替include RSpec::Matchers更正了此问题。在调试此问题并尝试整合pry时,我found this post提出了更改建议。

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

extend RSpec::Matchers

而不是

include RSpec::Matchers
相关问题