Bundler how to require gems separately in Gemfile just in one file?

断了今生、忘了曾经 提交于 2019-12-10 21:51:25

问题


I have a conflict between rspec and mocha (rspec is not using mocha but other minitest tests are).

If I put mocha in my gemfile (even with require: false) it gets loaded by activesupport/test_case.rb:15

silence_warnings { require 'mocha/setup' }

which then causes rspec to barf.

So, I'd like to just require it in my test_setup file from my system gems but I can't figure out how to load a gem outside of bundler.

Other ideas on how to get these gems to play nice are welcome.


回答1:


You can use groups in your Gemfile: http://bundler.io/v1.3/groups.html

Require the gems in particular groups, noting that gems outside of a named group are in the :default group

Bundler.require(:default, :development)  

Require the default gems, plus the gems in a group named the same as the current Rails environment

Bundler.require(:default, Rails.env)  

Restrict the groups of gems that you want to add to the load path. Only gems in these groups will be require'able

require 'rubygems'
require 'bundler'
Bundler.setup(:default, :ci)
require 'nokogiri'



回答2:


Could you just install gem and require it?

$ gem install my_gem

and in testfile:

require 'full/path/to/my_gem.rb'


来源:https://stackoverflow.com/questions/21738861/bundler-how-to-require-gems-separately-in-gemfile-just-in-one-file

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