Rails unit testing doesn't load fixtures

后端 未结 6 1088
梦谈多话
梦谈多话 2020-12-16 01:54

rake test:units fails in my current application, because the needed data of the fixtures is missing.

If I\'m loading the fixtures manually via rak

6条回答
  •  北海茫月
    2020-12-16 02:41

    Another approach is to write your own custom rake task for testing.

    For example:


    task :test_units do
    
      RAILS_ENV = 'test' # Force the environment to test
    
      puts "Recreate the test database"
      Rake::Task['db:test:prepare'].invoke
    
      puts "Seed the database with fixtures"
      Rake::Task['db:fixtures:load'].invoke
    
      puts "Executing Unit Tests"
      Rake::Task['test:units'].prerequisites.clear 
      Rake::Task['test:units'].invoke
    end
    

提交回复
热议问题