【发布时间】:2014-04-30 16:49:30
【问题描述】:
我正在尝试使用 rspec 测试我的 rake 任务,它运行良好,但问题是之后没有删除记录。
我已将config.use_transactional_fixtures = true 放在配置文件中,没有影响。在其他测试中它运行良好。
这是我的代码:
require 'rspec'
require 'spec_helper'
require 'rake'
describe 'my_app rake tasks' do
describe 'rake_task_1' do
before { MyApp::Application.load_tasks }
it 'should test it!' do
10.times { create(:record) }
Rake::Task["rake_task_1"].invoke
Record.count.should == 10
end
end
end
在我的 rake 任务中,我正在使用 ActiveRecord::Base.connection.execute 执行查询。
我确定它在 RSepc 中有一些与 SQL 转换有关的东西......
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails ruby rspec factory-bot