NoMethodError: undefined method `url_whitelist=' for DatabaseCleaner:Module

NoMethodError: undefined method `url_whitelist=' for DatabaseCleaner:Module

safeguard document section里面说我们可以指定白名单url:

In Ruby, a URL whitelist can be specified. When specified, DatabaseCleaner will only allow DATABASE_URL to be equal to one of the values specified in the url whitelist like so:

但是我得到了 NoMethodError:

require "database_cleaner"
DatabaseCleaner.url_whitelist = %w(mysql2://root@mysql)
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)

这个url_whitelist定义为here, introduced in this pull request

使用 DatabaseCleaner 1.7.0.

目前最新版本1.7.0不包含此方法‍♀️

从 2018 年 8 月 9 日起,暂时使用 master 分支。

您可以在 here 查看是否有更新的版本发布。