Rspec `要求';:无法加载此类文件--回形针/火柴(加载错误)

Rspec `要求';:无法加载此类文件--回形针/火柴(加载错误),rspec,paperclip,ruby-on-rails-5,shoulda,Rspec,Paperclip,Ruby On Rails 5,Shoulda,我使用的是rails 5.1.1和ruby 2.3.1 当我执行rspec时,我得到以下错误 `require':无法加载此类文件--回形针/匹配器(加载错误) 档案: gem“rspec-rails”,'>=3.6.0' gem“shoulda matchers”,“~>3.1” gem'shoulda callback matchers',“~>1.1.1' 我在spec_helper.rb中包含了以下内容 require "paperclip/matchers" config.inclu

我使用的是rails 5.1.1和ruby 2.3.1

当我执行rspec时,我得到以下错误

`require':无法加载此类文件--回形针/匹配器(加载错误)

档案:

gem“rspec-rails”,'>=3.6.0'
gem“shoulda matchers”,“~>3.1”
gem'shoulda callback matchers',“~>1.1.1'

我在spec_helper.rb中包含了以下内容

require "paperclip/matchers"

config.include Paperclip::Shoulda::Matchers

rspec似乎没有从rbenv gems文件夹加载与回形针相关的特定文件。

我假设您的实际GEM文件有更多条目。如果没有其他内容,您可能在顶部/附近有一个gem服务器:

source 'https://rubygems.org'
看起来,回形针宝石不是您列出的其他宝石的依赖项:

$ bundle show paperclip
Could not find gem 'paperclip' in any of the gem sources listed in your Gemfile.
因此,您可能还需要添加一行,例如:

gem 'paperclip'
然后运行
bundle安装
bundle显示回形针
。如果您仍然存在问题,可能是您尚未安装bundler以使用rbenv:

$ type bundle
bundle is hashed (/usr/local/bin/bundle)

$ gem install bundler
Fetching: bundler-1.15.1.gem (100%)
Successfully installed bundler-1.15.1
Parsing documentation for bundler-1.15.1
Installing ri documentation for bundler-1.15.1
Done installing documentation for bundler after 4 seconds
1 gem installed

$ rbenv rehash

$ type bundle
bundle is ~/.rbenv/shims/bundle

谢谢你的回复。我的档案里有回形针。我通过在rails\u helper.rb中的两行require“paperclip/matchers”config.include-paperclip::Shoulda::matchers解决了这个问题