我在测试rake任务时遇到问题。任务如下:
namespace :db do
desc 'Load the seed data from db/seeds.rb'
task :seed => :environment do
puts 'seed'
end
end
我的测试是这样的:
require 'rake'
require 'spec_helper'
RSpec.describe Rake::Task do
describe "db:seed" do
it "runs a task" do
Rake::Task['db:seed'].invoke
end
end
end
一切看起来都很好,但我还是犯了个错误:
Failure/Error: Rake::Task['db:seed'].invoke
RuntimeError:
Don't know how to build task 'db:seed' (See the list of available
tasks with `rake --tasks`)
最奇怪的是,当通过控制台调用时,同样的任务也能工作:
> rake db:seed
seed
有什么想法?