dzn*_*znz 7 rspec ruby-on-rails mongoid activeadmin
我有一个使用mongoid,database_cleaner和rspec的现有项目.我尝试使用可用的active_admin补丁添加active_admin .ActiveAdmin假定它在ActiveRecord项目中,最具体的是通过它对meta_search gem的依赖.
当我去运行我的规格时,它们都会因以下错误而失败:
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# ./spec/support/database_cleaner.rb:12:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
相关库的gem版本如下:
测试失败的文件,spec/support/database_cleaner.rb:
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
end
config.before(:each) do
DatabaseCleaner.clean
end
end
Run Code Online (Sandbox Code Playgroud)
Fél*_*lli 14
[移问问题]
似乎database_cleaner尝试在其初始化方法中自动检测可用的ORM
这可以通过更改spec/support/database_cleaner.rb文件来抢占:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner[:mongoid].strategy = :truncation
end
end
Run Code Online (Sandbox Code Playgroud)
[]在配置中调用方法会覆盖自动检测,以便不再添加ActiveRecord.
另一种解决方法是重新添加一个config/database.yml带有sqlite3配置的文件,该应用程序的其余部分将被忽略.值得庆幸的是没有必要.
| 归档时间: |
|
| 查看次数: |
2682 次 |
| 最近记录: |