With RSpec, how to seed the database on load?

后端 未结 6 1430
一个人的身影
一个人的身影 2021-01-30 03:28

I\'m using rspec for testing w my rails 3 app. I need to seed the database before the tests start. How can I seed the database with the following:

/db/seeds.rb

6条回答
  •  爱一瞬间的悲伤
    2021-01-30 03:58

    To load seeds in rspec you need to add it after database cleanup in confg.before(:suite) in spec_helper

    config.before(:suite) do
      DatabaseCleaner.clean_with(:truncation)
      load Rails.root.join('db', 'seeds.rb')
    end
    

提交回复
热议问题