Ruby on rails Rails在安装后测试不一致的数据

Ruby on rails Rails在安装后测试不一致的数据,ruby-on-rails,minitest,Ruby On Rails,Minitest,我一直在思考以下问题,但运气不佳: 为了测试rake任务是否正确填充了一些表,我有以下配置: class InitialDataTest < ApplicationSystemTestCase def setup DatabaseCleaner.clean_with :truncation, only: %w[centres projects departments] System::Application.load_tasks Rake::Task['popu

我一直在思考以下问题,但运气不佳: 为了测试rake任务是否正确填充了一些表,我有以下配置:

class InitialDataTest < ApplicationSystemTestCase
  def setup
    DatabaseCleaner.clean_with :truncation, only: %w[centres projects departments]
    System::Application.load_tasks
    Rake::Task['populate_lookup_tables:commit'].invoke

    sign_in users(:test_user)
  end

  test 'projects are created' do
    puts " Projects: #{Project.count}"
  end

  test 'centres are created' do
    puts "Centres: #{Centre.count}"
  end

  test 'departments are created' do
    puts " Departments: #{Department.count}"
  end
end
class InitialDataTest
我的rake任务实际上按预期工作(例如,在开发中),但是对于测试,似乎只填充了一个表:

Running via Spring preloader in process 15362
Started with run options --seed 17058

:: Centre populated successfully
:: Project populated successfully
:: Department populated successfully
>> OperationType is not empty
>> DocumentType is not empty
>> RecordErrorType is not empty

Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.3-p222), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:51272
Use Ctrl-C to stop
Departments: 5
Centres: 0
Projects: 0
3/3[========================================================] 100% Time: 00:00:03, Time: 00:00:03

Finished in 3.88633s
3 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to <My Stuff> (28.45%) covered.
在进程15362中通过弹簧预加载程序运行
从运行选项开始--种子17058
::中心已成功填充
::项目已成功填充
::已成功填充部门
>>OperationType不为空
>>DocumentType不为空
>>RecordErrorType不为空
Puma在单一模式下启动。。。
*版本3.9.1(ruby 2.3.3-p222),代码名:Private Caller
*最小线程数:0,最大线程数:1
*环境:测试
*倾听tcp://0.0.0.0:51272
使用Ctrl-C停止
部门:5
中心:0
项目:0
3/3[==============================================================================]100%时间:00:00:03,时间:00:00:03
以3.88633s完成
3次测试,0次断言,0次失败,0次错误,0次跳过
为单元测试生成的覆盖率报告覆盖率为(28.45%)。

默认情况下,Rake任务在给定上下文中只能调用一次。如果您想再次运行它,您需要调用
Rake::Task['populate\u lookup\u tables:commit']。首先重新启用

您完全正确!你能指出我可以从哪些资源中获得更多与本主题或类似主题相关的信息吗?我在这里找到的