Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle install via a CLI/Ruby system call?

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?

like image 765
easyjo Avatar asked Nov 22 '11 12:11

easyjo


People also ask

What is the bundle command?

The bundle exec command ensures that executable programs installed by Gems don't interfere with your app's requirements. For instance, if your app needs a specific version of rake but the default version of rake differs, bundle exec ensures that you can still run the specific rake version compatible with your app.

What is bundle exec command?

bundle exec is a Bundler command to execute a script in the context of the current bundle (the one from your directory's Gemfile). rake db:migrate is the script where db is the namespace and migrate is the task name defined.


1 Answers

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

Bundler.with_clean_env do
  system "shell out"
end    

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

like image 51
kangguru Avatar answered Nov 01 '22 07:11

kangguru