Bundler如何在Gemfile中分别需要一个文件中的gem? [英] Bundler how to require gems separately in Gemfile just in one file?
问题描述
我在rspec和mocha之间存在冲突(rspec不使用mocha,但是其他minitest测试)。
如果我将mocha放入我的gem文件中:false)它被activesupport / test_case.rb加载:15
silence_warnings {require'mocha / setup'}
然后导致rspec到barf。
我想从我的系统宝石中的test_setup文件中获取它,但我无法弄清楚如何在bundler之外加载gem。
其他想法如何让这些宝石发挥出色是值得欢迎的。
您可以在 Gemfile
: http://bundler.io/v1.3/groups.html
要求特定组中的宝石,注意
命名组之外的宝石位于:default组中Bundler.require(:默认,:开发)
需要默认的宝石,加上一个名为
的组中的宝石与当前的Rails环境相同Bundler.require(:default,Rails.env)
限制您想要添加到加载路径中的
宝石组。只有这些群体中的宝石将是
require'ablerequire'rubygems'
require'bundler'
Bundler.setup(:default,:ci)
require'nokogiri'
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.
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'
这篇关于Bundler如何在Gemfile中分别需要一个文件中的gem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!