Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compatible with ruby 3.0 #16

Open
rubydev opened this issue May 18, 2021 · 5 comments
Open

Not compatible with ruby 3.0 #16

rubydev opened this issue May 18, 2021 · 5 comments

Comments

@rubydev
Copy link

rubydev commented May 18, 2021

After upgrade Ruby to version 3.0.1 code is crashing:

config.before(:suite) do
  DatabaseCleaner[:mongoid].strategy = :deletion, { except: %w[roles exchange_rates] }
end
An error occurred in a `before(:suite)` hook.
Failure/Error: DatabaseCleaner[:mongoid].strategy = :deletion, { except: %w[roles exchange_rates] }

ArgumentError:
  wrong number of arguments (given 1, expected 0)
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-mongoid-2.0.1/lib/database_cleaner/mongoid/deletion.rb:9:in `initialize'
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:85:in `new'
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:85:in `create_strategy'
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:45:in `strategy='
# ./spec/rails_helper.rb:32:in `block (2 levels) in <top (required)>'

It looks, that it is related with DatabaseCleaner/database_cleaner#677

@botandrose
Copy link
Contributor

@rubydev Yes, that syntax no longer works in Ruby 3.0... you'll need to pass an array instead:

config.before(:suite) do
   DatabaseCleaner[:mongoid].strategy = [:deletion, except: %w[roles exchange_rates]]
end

I've updated the README to that syntax, while I was at it. I wonder if its possible to do a deprecation warning in < Ruby 3.0, and a more helpful error message in >= Ruby 3.0?

@rubydev
Copy link
Author

rubydev commented Jun 11, 2021

@botandrose Hello, thank you! But after change to array, result is same:

An error occurred in a `before(:suite)` hook.
Failure/Error: DatabaseCleaner[:mongoid].strategy = [:deletion, except: %w[roles exchange_rates]]

ArgumentError:
  wrong number of arguments (given 1, expected 0)
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-mongoid-2.0.1/lib/database_cleaner/mongoid/deletion.rb:9:in `initialize'
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:85:in `new'
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:85:in `create_strategy'
# /Users/marian/.rvm/gems/ruby-3.0.1@gre/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:45:in `strategy='
# ./spec/rails_helper.rb:32:in `block (2 levels) in <top (required)>'

Any idea why it doesn't work? Thank you!

@tstaetter
Copy link

same here, any solutions?

@tstaetter
Copy link

found a solution, works for me:

# inside rails_helper.rb
RSpec.configure do |config|
...
  # Clean DB after testing
  config.before :each do
    strategy = DatabaseCleaner::Mongoid::Deletion.new except: %w[<your collection names here>]
    DatabaseCleaner[:mongoid].instance_variable_set :'@strategy', strategy
    DatabaseCleaner[:mongoid].start
  end

  config.after do
    DatabaseCleaner[:mongoid].clean
  end
end

@rgaufman
Copy link

Thank you, that works for me too!

tobyprivett added a commit to DEFRA/waste-carriers-engine that referenced this issue Jan 26, 2022
- This came up when I was trying to squash some deprecation warnings

DatabaseCleaner/database_cleaner-mongoid#16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants