Why do I get an undefined method 'have' error when running Rspec?

好久不见. 提交于 2019-12-03 01:30:38

The have family of matchers was deprecated in RSpec 2.99 and has been moved to a separate rspec-collection_matchers gem as of RSpec 3.0. This is discussed in http://myronmars.to/n/dev-blog/2013/11/rspec-2-99-and-3-0-betas-have-been-released, which also gives the suggested approach to migrating to 3.0. Specifically, it recommends installing/using RSpec 2.99 in order to see the deprecation messages associated with items that were removed/moved in 3.0.

In the latest versions of rspec "have" being deprecated, but you still can use it via rspec-collection_matchers gem.

# Gemfile
...
gem 'rspec-collection_matchers', group: :test
...

# spec/spec_helper.rb
...
require 'rspec/collection_matchers'
....

OK, got it.

I had the wrong version number in my Gemfile.

Before:

gem 'rspec-rails', '~> 3.0.0.beta'

After:

gem 'rspec-rails'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!