"Environment data not found in the schema." 在 Rails 6 上重复调用 cucumber 时使用数据库清理器

"Environment data not found in the schema." with database-cleaner when calling cucumber repeatedly on Rails 6

注意: 这不是 的复制品,尽管它很相似。受影响的版本不同,我的解决不了。

我的 Rails 设置如下:

每当我第二次或以后 运行 cucumber 时,我都会收到此错误:

3924 ~/fork/my-proj$ bundle exec cucumber
rails aborted!
ActiveRecord::NoEnvironmentInSchemaError: 

Environment data not found in the schema. To resolve this issue, run: 

        rails db:environment:set RAILS_ENV=test

/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.1/lib/active_record/migration.rb:1151:in `last_stored_environment'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.1/lib/active_record/tasks/database_tasks.rb:60:in `check_protected_environments!'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.1/lib/active_record/railties/databases.rake:15:in `block (2 levels) in <main>'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.1/lib/active_record/railties/databases.rake:491:in `block (3 levels) in <main>'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/railties-6.0.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/railties-6.0.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/railties-6.0.1/lib/rails/command.rb:48:in `invoke'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/railties-6.0.1/lib/rails/commands.rb:18:in `<main>'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:325:in `block in require'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/grantb/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:325:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:test:load => db:test:purge => db:check_protected_environments
(See full trace by running task with --trace)
Using the default profile...
[...cucumber continues as normal...]

我怎么才能摆脱它?

如果我 运行 rails db:environment:set RAILS_ENV=test,它将在 cucumber 的下一个 运行 摆脱它,但它总是会在 运行之后。

我找到了另一个建议将其添加到我的配置中的答案,但是它什么也没做:

# This did NOT fix my problem:
DatabaseCleaner.clean_with(
  :truncation,
  except: %w(ar_internal_metadata)
)

很明显database_cleaner正在删除环境数据,但我不知道如何让它停止。

谁能帮我摆脱这个烦人的警告?

原来这个问题是 database_cleaner 1.7.

特有的

最近升级到 1.8.3 使此错误不再发生。

(associated Github issue)