У меня есть Rails API, который я пытаюсь протестировать с помощью Rspe c. Я добавил в DatabaseCleaner для mongoid
в Gemfile и запустил sudo bundle install
, но я получаю сообщение об ошибке ниже.
Мне не хватает конфигурации в любом из них?
The DatabaseCleaner::Mongoid adapter has been extracted to its own gem: database_cleaner-mongoid, and will be removed from database_cleaner in 2.0. To silence this message, please replace `gem "database_cleaner"` with `gem "database_cleaner-mongoid"` in your Gemfile.
F
Failures:
1) Users POST /api/v1/users creates a new user with valid details
Failure/Error: DatabaseCleaner.strategy = :transaction
DatabaseCleaner::UnknownStrategySpecified:
The 'transaction' strategy does not exist for the mongoid ORM! Available strategies: truncation
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:150:in `rescue in require_orm_strategy'
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:146:in `require_orm_strategy'
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:142:in `rescue in orm_strategy'
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:133:in `orm_strategy'
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:112:in `create_strategy'
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:34:in `strategy='
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/configuration.rb:19:in `block in strategy='
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/configuration.rb:19:in `each'
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/configuration.rb:19:in `strategy='
# ./spec/rails_helper.rb:42:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
# uninitialized constant DatabaseCleaner::Mongoid::Transaction
# Did you mean? DatabaseCleaner::Mongoid::Truncation
# /var/lib/gems/2.5.0/gems/database_cleaner-1.8.4/lib/database_cleaner/base.rb:135:in `const_get'
Finished in 0.18763 seconds (files took 2.8 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/requests/users_request_spec.rb:18 # Users POST /api/v1/users creates a new user with valid details
Gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'database_cleaner-mongoid'
end
rails_helper.rb
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.before(:all) do
DatabaseCleaner.start
end
config.after(:all) do
DatabaseCleaner.clean
end
end