How to stop rspec from resetting the test database to testing

I have two Rails applications that use the same database. One application manages the database through migrations, and the other simply accesses it.

For some reason, when I run tests with RSpec in an application that does not manage the database, it drops the database before running the tests. But since this application does not know how to recreate the database, all tests will fail.

How can I tell RSpec not to drop the database, just use it the way it is?

+4
source share
2 answers

, rspecs-rails spec:prepare :

lib/tasks/patch_rspec_rails.rb

Rake::Task["spec:prepare"].clear
namespace :spec do
  task :prepare do
    ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
  end 
end

spec:prepare test:prepare, db.

test:prepare Rails 4.0 (, , ). Rails 5.0. , . rake -W test:prepare. , rake --trace spec.

ActiveRecord , db.

, db .

, - test:prepare, , .

:

Rails 4.1 config.active_record.maintain_test_schema = false config/environments/test.rb. , Rails .

+6

RSpec , , , .

- Rails, , rake db:schema:dump schema.rb, RSpec - , , test.yml .

, , , - .

+2

Source: https://habr.com/ru/post/1658813/


All Articles