是否可以使用代码中的“bundle exec”功能?

时间:2012-09-17 17:46:17

标签: ruby rspec bundler

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

通常,我会在命令行上写一下:

bundle exec rspec

有没有办法可以实现同样的目的,但是以编程方式实现?

2 个答案:

答案 0 :(得分:2)

如果你想用捆绑的宝石运行一些红宝石,你只需要“捆绑/设置”:

require 'bundler/setup'
require 'rspec' # loads the version specified in Gemfile

答案 1 :(得分:0)

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

def run_specs
    `bundle exec rspec | grep foo`
end
相关问题