Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为一些工具构建一个 Web 界面,并且我希望能够在 Bundler 上下文中运行命令或 gem,就像“bundle exec”命令一样,除了在我的代码中。
所以通常,我会在命令行上写:
bundle exec rspec
有没有办法我可以实现同样的事情,但以编程方式?
如果你想用捆绑的 gem 运行一些 ruby,你可以只需要“bundler/setup”:
require 'bundler/setup' require 'rspec' # loads the version specified in Gemfile
您可以在 Ruby 中将 shell 命令包装在反引号 (`) 中。
def run_specs `bundle exec rspec | grep foo` end