With RSpec, how to seed the database on load?

后端 未结 6 1499
一个人的身影
一个人的身影 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:52

    However Scott's solution surely works for you, I believe the better way to solve your problem was to put the code responsible for seeding your test database within RSpec's configure block:

    I use SeedFu and in my spec_helper I have:

    RSpec.configure do |config|
    
      # some other configuration code ...
    
      config.before(:suite) do
        # ...
        SeedFu.seed
        # ...
      end
    
      # some other configuration code ...
    
    end
    

提交回复
热议问题