Installing a package through a CLI / Ruby call

Is it possible to start package installation from the ruby ​​system call?

I am trying to set gems and run tests for a project under a different path ...

For example, the command:

"cd /some/other/project && bundle install && gem list && rspec spec"

Ideally, I want to just run the tests through the rake file in one project, making sure that the appropriate stones for this project are installed.

It seems that cd is working correctly if I run:

"cd /some/other/project && pwd"

This gives the right way. But if I am going to install install && gem, it seems that it installs gems for the current folder and does not use the Gemfile from another project, and then the rspec specification does not work.

To summarize, what is the best way to run the "rspec spec", for example, for another project in rakefile, also ensure the availability of the corresponding gems?

+5
3

, :

Bundler.with_clean_env do
  system "shell out"
end    

google: https://groups.google.com/d/msg/ruby-bundler/UufhzrliWfo/d51B_zARksUJ

+6

: , . , :

#@pwd is the "working directory of the execution...

Dir.chdir @pwd do
  so = ""
  vars = {
         "BUNDLE_GEMFILE" => nil,
         "BUNDLE_BIN_PATH" => nil,
         "RUBYOPT" => nil,
         "rvm_" => nil,
         "RACK_ENV" => nil,
         "RAILS_ENV" => nil,
         "PWD" => @pwd 
       }
  options = {
            :chdir=>@pwd
          }
  Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr|
    stdin.close_write
    so = stdout.read
    so = stderr.read if so.nil? || so == ""
  end

  so
end

: . , - exec | install | update, ,

bash -c "cd ../other/; bundle install; and it fails" open3.popen( "bundle install",: chdir = > "../other" )

- , , , .

open3.popen( "bundle install", {: chdir = > "../other",: unsetenv_others = > false}) RVM ;

0

In addition to kangguru answer you may need

bundle install --deployment

So Bundler.with_clean_env will not be corrupted by rvm. This sets up copies of all your gems in the .vendor / bundle in the root of your project, which is then selected by the Bundler.with_clean_env team.

(I would put it as a comment, but I don't have a 50+ reputation)

0
source

All Articles