Pra*_*ams 11 ruby ruby-on-rails capybara ruby-on-rails-3
无法使用清理数据database_cleaner.rb; 在运行测试时抛出以下问题.
/Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p598/gems/database_cleaner-1.3.0/lib/database_cleaner/base.rb:147:in"autodetect":未检测到已知的ORM!ActiveRecord,DataMapper,Sequel,MongoMapper,Mongoid,Moped或CouchPotato,Redis还是Ohm加载?(DatabaseCleaner :: NoORMDetected)

spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = false
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.color = true
Selenium::Application.reload_routes!
end
Run Code Online (Sandbox Code Playgroud)
database_cleaner.rb
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
end
Run Code Online (Sandbox Code Playgroud)
我在controller_spec上遇到了同样的问题。
'autodetect': No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded? (DatabaseCleaner::NoORMDetected)
我通过在控制器规格上要求rails_helper文件来解决。
require 'rails_helper'
Run Code Online (Sandbox Code Playgroud)
在rails_helper.rb中,需要文件“ database_cleaner”。
require 'database_cleaner'
Run Code Online (Sandbox Code Playgroud)
使用我的设置,似乎适用于 RDBMS(在 MySQL 和 Postgres 上检查),将其放入您的database_cleaner.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
# this may be needed for Capybara tests and for testing after_commit hooks
config.before(:each, strategy: :truncation) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Run Code Online (Sandbox Code Playgroud)
如果你想使用truncation策略,只需使用
describe 'something', strategy: :truncation或it 'something', strategy: truncation。
| 归档时间: |
|
| 查看次数: |
1601 次 |
| 最近记录: |