如何在Rails控制台中使用FactoryGirl中的工厂 [英] How do I use factories from FactoryGirl in rails console

查看:49
本文介绍了如何在Rails控制台中使用FactoryGirl中的工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发环境中使用Rails控制台,并且想使用工厂.如何获得它们的访问权限?

I am using rails console in the development environment and I want to use factories. How can I get access to them?

我已经尝试要求返回

I have tried require "FactoryGirl" which returns

1.9.3p393 :301 > require "FactoryGirl"
LoadError: cannot load such file -- FactoryGirl

推荐答案

要解决此问题,请确保在您的Gemfile中指定与此类似的工厂bot gem

To solve this problem ensure that the factory bot gem is specifed in your Gemfile similar to this

group :development, :test do
  gem 'factory_bot_rails'
end

然后捆绑安装.

这应该使FactoryBot类在开发控制台中可用.

This should make FactoryBot class available in the development console.

希望这会有所帮助.

这篇关于如何在Rails控制台中使用FactoryGirl中的工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆