我有一个使用mongoid,database_cleaner和rspec的现有项目.我尝试使用
active_admin patches available添加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)>'
相关库的gem版本如下:
> activeadmin(0.4.2)
> database_cleaner(0.7.1)
> mongoid(2.4.5)
> meta_search(1.1.3)
> activerecord(3.2.1)
测试失败的文件,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
解决方法
[移问问题]
似乎database_cleaner尝试在its initialization method中自动检测可用的ORM
这可以通过更改spec / support / database_cleaner.rb文件来抢占,如下所示:
RSpec.configure do |config| config.before(:suite) do DatabaseCleaner[:mongoid].strategy = :truncation end end
在configuration中调用[]方法会覆盖自动检测,以便不再添加ActiveRecord.
另一种解决方法是重新添加一个带有sqlite3配置的config / database.yml文件,该应用程序的其余部分将被忽略.谢天谢地,没有必要.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。