Question

I have a Rails 3.2 project that is a git repo and inside the vendor/autotest-new directory I have a git submodule.

I want to use Thor to automate some actions. For example I need to perform cucumber -d -f json > test.json inside the git submodule.

Manually it works fine, but when I run the thor task it throws an error:

/home/user/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem': cucumber is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
  from /home/user/.rvm/gems/ruby-2.0.0-p247@rails32/bin/cucumber:22:in `<main>'
  from /home/user/.rvm/gems/ruby-2.0.0-p247@rails32/bin/ruby_noexec_wrapper:14:in `eval'
  from /home/user/.rvm/gems/ruby-2.0.0-p247@rails32/bin/ruby_noexec_wrapper:14:in `<main>'

I've already run bundle install inside the submodule.

The thor task is:

class DB < Thor

  include Thor::Actions

  desc 'test_task',  "test task"
  def test_task
    Dir.chdir("vendor/autotest-new") do
      puts `bundle exec cucumber -d -f json > test.json`
    end
  end
end

I've also tried

run "bundle exec cucumber -d -f json > test.json"
system "bundle exec cucumber -d -f json > test.json"

But it didn't help.

Was it helpful?

Solution

It's not Thor, it's bundler.

Answer is here https://github.com/bundler/bundler/issues/1579

I need to use execute that commands in the block

Bundler.with_clean_env do
  #my commands
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top