Rails 4.1.8中的“无法加载此类文件

编程入门 行业动态 更新时间:2024-10-26 18:28:32
本文介绍了Rails 4.1.8中的“无法加载此类文件-factory_girl_rails(LoadError)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

运行rspec时,出现以下错误:

While running rspec, I am getting the following error:

/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- factory_girl_rails (LoadError) from /Users/radhikabhatt/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Users/radhikabhatt/Desktop/work/cl_portalmiudla/spec/spec_helper.rb:19:in <top (required)>' from /Users/radhikabhatt/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Users/radhikabhatt/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

我的gemfile.lock看起来像:

My gemfile.lock looks like:

factory_girl (4.5.0) activesupport (>= 3.0.0) factory_girl_rails (4.5.0) factory_girl (~> 4.5.0)

spec_helper.rb具有require 'factory_girl_rails'行.请让我知道我是否错过了这里.

spec_helper.rb has the line require 'factory_girl_rails'. Please let me know if I missed something here.

推荐答案

factory_girl_rails是railtie gem,这意味着它将挂接到rails生命周期并进行注册.因此,您不需要隐式要求它.实际上,您甚至不能要求使用它,这是问题中的错误原因.您需要做的只是将其包含在Gemfile中并捆绑在一起.然后,您将获得factory_girl的生成器.

factory_girl_rails is a railtie gem which means it will hook into the rails lifecycle and register itself. So you don't need to require it implicitly. In fact you even cannot require it which is the cause of error in your question. All you need to do is just include it in the Gemfile and bundle it. Then you get generators for factory_girl along with it.

为了将factory_girl与rspec一起使用,可以按如下所示在spec_helper.rb中添加:

In order to use factory_girl with rspec, you can add in you spec_helper.rb as follow:

# RSpec # spec/support/factory_girl.rb RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods end

它取自 factory_girl文档

更多推荐

Rails 4.1.8中的“无法加载此类文件

本文发布于:2023-10-16 16:59:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:此类   加载   文件   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!