本文介绍了如何通过CLI / Ruby系统调用捆绑安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从ruby系统调用中运行软件包安装?

Is it possible to run bundle install from a ruby system call?

我正在尝试安装gems并在另一个路径下为项目运行测试...

I'm trying to install gems and run tests for a project under another path...

例如命令是:

"cd /some/other/project && bundle install && gem list && rspec spec"

理想情况下,我只想通过一个项目中的rake文件运行测试,同时确保已安装该项目的相关gem。

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.

该CD似乎工作正常,如果我运行:

The cd seems to be working correctly, if I run:

"cd /some/other/project && pwd"

它确实给出了正确的路径。但如果我捆绑安装&&在gem环境中,似乎为当前文件夹安装了gems,并且未使用其他项目中的Gemfile,因此rspec规范不起作用。

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.

总结一下,例如,对于rakefile中的另一个项目,还要确保相关的gem可用,运行 rspec spec的最佳方法是什么?

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?

推荐答案

实际上看来,实现此行为的官方方法是这样的:

Actually it looks that the official way to achieve this behavior is like this:

Bundler.with_clean_env do
  system "shell out"
end    

我在Google网上论坛找到了答案:

I found the answer over at google groups: https://groups.google.com/d/msg/ruby-bundler/UufhzrliWfo/d51B_zARksUJ

这篇关于如何通过CLI / Ruby系统调用捆绑安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:19