`ruby -S rake spec`在命令行中运行正常,但在Ruby执行`sh“ruby -S rake spec”时则不行

时间:2014-09-27 18:26:47

标签: ruby rspec rakefile

我有以下目录结构:

parent/
    Rakefile
    child/
        Rakefile

我的Rakefiles看起来像这样:

# parent/Rakefile
task :spec do
  Dir.chdir(File.join File.dirname(__FILE__), 'child') do
    sh "ruby -S rake spec"
  end 
end

# parent/child/Rakefile
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new :spec do |task|
  task.rspec_opts = %w(--color --format documentation)
end

如果我在ruby -S rake spec内执行parent/child,则规格会正确运行。如果我在rake spec内执行parent/,我会收到以下错误:

LoadError: cannot load such file -- rspec/core/rake_task
/workplace/max/parent/child/Rakefile:2:in `require'
/workplace/max/parent/child/Rakefile:2:in `<top (required)>'
/Users/max/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/max/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
rake aborted!

值得注意的是,rspec在parent/child的包中,但rspec不在parent/的包中

0 个答案:

没有答案