我正在尝试为一些rake任务编写一些基本的冒烟测试。由于我不理解的原因,如果两个都没有注释,我会收到Don't know how to build task...
错误。如果我推荐 一个,它可以正常工作(按任何顺序)。
规格/任务/ foo_spec.rb
require "rails_helper"
require "rake"
describe "Foo rake tasks" do
before do
@rake = Rake::Application.new
Rake.application = @rake
Rake.application.rake_require "../rakelib/foo"
Rake::Task.define_task(:environment)
end
describe "rake foo:bar" do
before do
@task_name = "foo:bar"
end
it "runs without errors" do
expect { @rake[@task_name].invoke('1') }.not_to raise_error
end
end
describe "rake foo:rab" do
before do
@task_name = "foo:rab"
end
it "runs without errors" do
expect { @rake[@task_name].invoke('1', 'boo') }.not_to raise_error
end
end
end
end
此设置是this tutorial的改编。
答案 0 :(得分:0)
这里有什么效果,改编自this。
require "rails_helper"
require "rake"
describe "Foo rake tasks" do
before :all do
Rake.application.rake_require "../rakelib/foo"
Rake::Task.define_task(:environment)
end
describe "rake foo:bar" do
let :run_rake_task do
Rake::Task["foo:bar"].reenable
Rake.application.invoke_task "foo:bar"
end
it "runs without errors" do
expect { run_rake_task }.not_to raise_error
end
end
end