我有以下目录结构:
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/
的包中