2

我正在为一些工具构建一个 Web 界面,并且我希望能够在 Bundler 上下文中运行命令或 gem,就像“bundle exec”命令一样,除了在我的代码中。

所以通常,我会在命令行上写:

bundle exec rspec

有没有办法我可以实现同样的事情,但以编程方式?

4

2 回答 2

2

如果你想用捆绑的 gem 运行一些 ruby​​,你可以只需要“bundler/setup”:

require 'bundler/setup'
require 'rspec' # loads the version specified in Gemfile
于 2012-09-17T18:15:18.383 回答
0

您可以在 Ruby 中将 shell 命令包装在反引号 (`) 中。

def run_specs
    `bundle exec rspec | grep foo`
end
于 2012-09-17T18:05:13.177 回答