我试图让 DatabaseCleaner 在我使用 Sequel 的非 Rails 应用程序上运行,但我遇到了各种各样的问题。看起来数据库设置不正确 -
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
p DatabaseCleaner.connections
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
运行 rspec 返回 -
ruby-1.9.2-p290/gems/database_cleaner-0.8.0/lib/database_cleaner/sequel/truncation.rb:12:in `clean': undefined method `url' for :default:Symbol (NoMethodError)
from /Users/tim/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.8.0/lib/database_cleaner/base.rb:39:in `clean_with'
from /Users/tim/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.8.0/lib/database_cleaner/configuration.rb:62:in `block in clean_with'
from /Users/tim/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.8.0/lib/database_cleaner/configuration.rb:62:in `each'
from /Users/tim/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.8.0/lib/database_cleaner/configuration.rb:62:in `clean_with'
The line this is failing on -
case db_type= db.url.sub(/:.+/,'').to_sym
If I remove 'DatabaseCleaner.clean_with(:truncation)' I get the following, notice the DB is set to :default and not :test
[#<DatabaseCleaner::Base:0x007fdbe41825f0 @autodetected=true, @orm=:sequel, @strategy=#<DatabaseCleaner::Sequel::Transaction:0x007fdbe416b328 @db=:default>>]
An error occurred in an after hook
NoMethodError: undefined method `resume' for nil:NilClass occurred at /Users/tim/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.8.0/lib/database_cleaner/sequel/transaction.rb:22:in `clean'
Both errors indicate that the DB hasn't been set, but I can't see why. Any ideas?