Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RSPEC-从加载时的文件还原数据库_Ruby On Rails_Postgresql_Rspec - Fatal编程技术网

Ruby on rails RSPEC-从加载时的文件还原数据库

Ruby on rails RSPEC-从加载时的文件还原数据库,ruby-on-rails,postgresql,rspec,Ruby On Rails,Postgresql,Rspec,我有一个rails项目运行rspec进行测试,我希望在每次启动rspec时从转储文件恢复测试数据库。我尝试在rspec块下的rails\u helper文件中编写一些配置,但由于数据库正在使用,它无法使用系统命令还原数据库 加载rspec时,如何从转储文件恢复DB 使用Rails 5和psql,我能够通过在RSpec configure块下的Rails\u helper中执行以下操作来解决这个问题: ActiveRecord::Base.connection.disconnect! sy

我有一个rails项目运行rspec进行测试,我希望在每次启动rspec时从转储文件恢复测试数据库。我尝试在rspec块下的
rails\u helper
文件中编写一些配置,但由于数据库正在使用,它无法使用系统命令还原数据库

加载rspec时,如何从转储文件恢复DB


使用Rails 5和psql,我能够通过在RSpec configure块下的Rails\u helper中执行以下操作来解决这个问题:

  ActiveRecord::Base.connection.disconnect!
  system('bin/rails db:environment:set RAILS_ENV=test')
  system('rake db:drop')
  system('rake db:create')
  system('pg_restore --no-acl --no-owner -d name_of_databse test.dump')
  ActiveRecord::Base::establish_connection

我可以通过在RSpec configure块下的
rails\u helper
中执行以下操作来解决此问题:

  ActiveRecord::Base.connection.disconnect!
  system('bin/rails db:environment:set RAILS_ENV=test')
  system('rake db:drop')
  system('rake db:create')
  system('pg_restore --no-acl --no-owner -d name_of_databse test.dump')
  ActiveRecord::Base::establish_connection