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?
Edit: I think I have it figure out. see if this works for you:
Original Post: I am tearing my hair out with this. I think it has something to do with bundle exec|install|update setting environment variables when you start up the application, I have tried
bash -c "cd ../other/; bundle install; and it fails"
I have tried using open3.popen("bundle install", :chdir=>"../other")if it is any consolation you are not crazy, but I to can't seem to figure out how to fix it.
I also tried open3.popen("bundle install", {:chdir=>"../other", :unsetenv_others => false}) but this ends up up removing RVM from the system path;
In addition to kangguru's answer, you might need to do
So that the Bundler.with_clean_env doesn't get messed up by rvm. This installs copies of all your gems to .vendor/bundle in the root of your project, which is then picked up by the Bundler.with_clean_env command.
(Would have put this as a comment but I don't have 50+ reputation)
Actually it looks that the official way to achieve this behavior is like this:
I found the answer over at google groups: https://groups.google.com/d/msg/ruby-bundler/UufhzrliWfo/d51B_zARksUJ