3

Rails 4 アプリのいくつかのテストを完了しようとしていますが、database_cleaner で問題が発生し続けています。問題は、データベースがクリーンアップされておらず、警告が発生し続けることです。

DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
.DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress
.FFFFDEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
.DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
WARNING:  there is already a transaction in progress
.DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
WARNING:  there is already a transaction in progress
.WARNING:  there is already a transaction in progress
DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
.DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
WARNING:  there is already a transaction in progress
.DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
WARNING:  there is already a transaction in progress
.DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from block (3 levels) in <top (required)> at /Users/davidhahn/Dev/cta-projects/user-management2/spec/spec_helper.rb:49)
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress

仕様ヘルパーでセットアップした構成は次のとおりです。

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.

  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  # require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/rspec'
  require 'database_cleaner'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  # config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.filter_run focus: true
  config.run_all_when_everything_filtered = true

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  # config.use_transactional_fixtures = false

  config.before :each do
    if Capybara.current_driver == :rack_test
      DatabaseCleaner.strategy = :transaction
    else
      DatabaseCleaner.strategy = :truncation
    end
    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end


  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  # config.infer_base_class_for_anonymous_controllers = false

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = "random"
  end
end

そして最後に、これが私のgemfileです

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.beta1'

gem 'pg'
gem 'haml-rails', '~> 0.4'
gem 'twitter-bootstrap-rails', '~> 2.2.0'
gem 'annotate', '~> 2.5.0'
group :test do
  gem 'rspec', '~> 2.13.0'
  gem 'rspec-rails', '~> 2.13.0'
  gem 'guard-rspec', '~> 1.2.1'
  gem 'guard-spork', '~> 1.4.2'
  gem 'capybara', '~> 2.0.2'
  gem 'spork', '~> 0.9.2'
  gem 'factory_girl_rails', '~> 4.1.0'
  gem 'shoulda-matchers', '~> 1.4.2'
  gem 'database_cleaner', '~> 0.9.1'
  gem 'launchy', '~> 2.2.0'
  gem 'rb-fsevent', '~> 0.9.2'
  gem 'growl', '~> 1.0.3'
end

group :development do
  gem 'better_errors' ,'~> 0.6.0'
  gem 'binding_of_caller', '~> 0.7.1'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 4.0.0.beta1'
  gem 'coffee-rails', '~> 4.0.0.beta1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', platforms: :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.0.1'

この問題に関するヘルプは本当に役に立ちます。ありがとうございました!

4

1 に答える 1

11

これは、database_cleaner の 1.0.0 RC1 リリースで修正されたようです。Gemfile でこれを試してください:

gem "database_cleaner", '1.0.0.RC1'
于 2013-04-16T03:18:44.760 に答える