Rails 5,Rspec:在架构中找不到环境数据 [英] Rails 5, Rspec: Environment data not found in the schema
问题描述
将 Rails 应用升级到 Rails 5 后,运行 RSpec 测试出现以下错误:
After upgrading a Rails app to Rails 5, running RSpec tests gives me the following error:
rails aborted!
ActiveRecord::NoEnvironmentInSchemaError:
Environment data not found in the schema. To resolve this issue, run:
bin/rails db:environment:set RAILS_ENV=test
但是,那个 bin
不存在,我似乎无法用 bundle binstubs rails
或 rake rails:update:bin生成它代码>.
However, that bin
does not exist and I can't seem to generate it with bundle binstubs rails
or with rake rails:update:bin
.
我也试过:
rails db:environment:set RAILS_ENV=test
rake db:environment:set RAILS_ENV=test
Github 上有一个相关问题这里.
There is a related issue on Github here.
我该如何解决这个错误?
How can I address this error?
推荐答案
用于生成 binstubs 的新 Rails 5 命令:
New Rails 5 command to generate binstubs:
rails app:update:bin
允许我按照错误提示运行解决方案:
Allows me to run the solution as the error suggested:
bin/rails db:environment:set RAILS_ENV=test
来自@max 评论的提示:如果您正在使用 database_cleaner
并且此错误不断弹出,则将您的配置更改为:
Tip from @max comment: If you are using database_cleaner
and this error keeps popping up then change your config to:
DatabaseCleaner.clean_with(
:truncation,
except: %w(ar_internal_metadata)
)
这篇关于Rails 5,Rspec:在架构中找不到环境数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!