如何通过 CLI/Ruby 系统调用捆绑安装?
是否可以通过 ruby 系统调用运行捆绑安装?
我正在尝试安装 gems 并在另一路径下运行项目测试...
例如命令是:
"cd /some/other/project && bundle install && gem list && rspec spec"
理想情况下,我想通过一个项目中的 rake 文件运行测试,同时确保该项目的相关 gems 是安装。
如果我运行的话,CD 似乎工作正常:
"cd /some/other/project && pwd"
它确实给出了正确的路径。但如果我捆绑安装 && gem 环境,它似乎为当前文件夹安装了 gem,并且不使用其他项目中的 Gemfile,因此 rspec 规范不起作用。
总而言之,例如,对于 rakefile 中的另一个项目运行“rspec spec”的最佳方式是什么,同时确保相关的 gem 可用?
Is it possible to run bundle install from a ruby system call?
I'm trying to install gems and run tests for a project under another path...
For example the command is:
"cd /some/other/project && bundle install && gem list && rspec spec"
Ideally I want to just run the tests via a rake file in one project whilst making sure the relevant gems for that project are install.
The cd seems to be working correctly, if I run:
"cd /some/other/project && pwd"
It does give the correct path. But if I do bundle install && gem environment, it seems to install the gems for the current folder and doesn't use the Gemfile from the other project, and subsequently the rspec spec doesn't work.
To summarize, what's the best way to run 'rspec spec' for example, for another project within a rakefile also ensuring the relevant gems are available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,实现这种行为的官方方法看起来是这样的:
我在谷歌群组中找到了答案:https://groups.google.com/d/msg/ruby-bundler/UufhzrliWfo/d51B_zARksUJ
Actually it looks that the official way to achieve this behavior is like this:
I found the answer over at google groups: https://groups.google.com/d/msg/ruby-bundler/UufhzrliWfo/d51B_zARksUJ
编辑:
我想我已经弄清楚了。看看这是否适合您:
原始帖子:
我对此感到抓狂。我认为这与启动应用程序时的bundle exec|install|update 设置环境变量有关,我尝试过
bash -c "cd ../other/;bundle install; 但失败了"
我尝试过使用
open3.popen("bundle install", :chdir=>"../other")
如果有任何安慰的话,你没有疯,但我似乎不知道如何解决它。
我也尝试过
open3.popen("捆绑安装", {:chdir=>"../other", :unsetenv_others => false})
但这最终会从系统路径中删除 RVM;
Edit:
I think I have it figure out. see if this works for you:
Original Post:
I am tearing my hair out with this. I think it has something to do with bundle exec|install|update setting environment variables when you start up the application, I have tried
bash -c "cd ../other/; bundle install; and it fails"
I have tried using
open3.popen("bundle install", :chdir=>"../other")
if it is any consolation you are not crazy, but I to can't seem to figure out how to fix it.
I also tried
open3.popen("bundle install", {:chdir=>"../other", :unsetenv_others => false})
but this ends up up removing RVM from the system path;
除了 kangguru 的答案之外,您可能还需要这样做
,以便 Bundler.with_clean_env 不会被 rvm 弄乱。
这会将所有 gem 的副本安装到项目根目录中的 .vendor/bundle 中,然后由 Bundler.with_clean_env 命令获取。
(本来可以将此作为评论,但我没有 50+ 声誉)
In addition to kangguru's answer, you might need to do
So that the Bundler.with_clean_env doesn't get messed up by rvm.
This installs copies of all your gems to .vendor/bundle in the root of your project, which is then picked up by the Bundler.with_clean_env command.
(Would have put this as a comment but I don't have 50+ reputation)