10

对于测试的每个步骤发生 2 行:

WARNING:  there is already a transaction in progress
NOTICE:  there is no transaction in progress

Spork 线跟随三元组:

NOTICE:  there is no transaction in progress
NOTICE:  there is no transaction in progress
NOTICE:  there is no transaction in progress
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress

我不知道这可能很重要,只是警告过。宝石文件:

group :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'spork-rails'
  gem 'capybara'
  gem 'database_cleaner'
end

都是定制的,所以不需要开发组,反正也没用。这是 spec_helper。我发现它是 PostgreSQL 功能,但我找不到如何修复它。我将不胜感激

4

2 回答 2

11

在 spec_helper.rb

config.use_transactional_examples = false #factoryGirl
config.use_transactional_fixtures = false #fixtures

config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

在数据库.yml

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: myapp_test
  username: my_username
  password:
  allow_concurrency: true
  pool: 5
  min_messages: error

即使您设置了 min_messages 选项,您仍然可能会看到如下控制台输出:

WARNING:  there is already a transaction in progress

编辑文件

/opt/local/var/db/postgresql92/defaultdb/postgresql.conf

并设置以下内容:

client_min_messages = error

现在一切都应该顺利进行。

于 2013-02-06T14:47:15.347 回答
9

spec_helper.rb,我会尝试改变这个

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

对此

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end 
于 2012-09-18T17:14:05.723 回答