我的rake任务有User.create
,但此代码不起作用:
require 'rake'
require 'rails_helper'
feature "Should create a user when running task" do
describe "should create user" do
Rails.application.load_tasks
Rake::Task['make_a:new_user'].invoke
expect(User.count).to be(1)
end
end
我得到了
expected #<Fixnum:3> => 1
got #<Fixnum:1> => 0
我的rake文件:
namespace :make_a do
desc "Create a new user"
task :new_user => :environment do
User.create(email: "test@gmail.com", password: "test")
end
end