How do I run Rails integration tests without dropping DB contents?

后端 未结 4 1891
故里飘歌
故里飘歌 2021-01-02 04:22

I\'ve written some integration tests that I\'d like to run against a copy of my prod database before I push to production. This lets me test all of my routes are still corre

4条回答
  •  攒了一身酷
    2021-01-02 04:29

    To get this to work I had to specifiy the environment when calling the rake task, otherwise it would run the migrations on the development db and then run the tests on the test db; given the example from above

    namespace :dbtest do
      Rake::TestTask.new(:integration => "db:migrate") do |t|
        ...
    

    I had to execute the tests like so

    rake environment RAILS_ENV=test dbtest:integration
    

提交回复
热议问题