3

きゅうりのテスト ケースを作成しましたが、既存のデータベースではなくデータベースをロールバックする必要があります。カピバラ 2.0.2 でセレン Web ドライバーを使用しています。私が試したとき:

DatabaseCleaner[:active_record].strategy = :truncation

私のmysqlテーブルのすべてのレコードが削除されます。その後、私はこれを次のように変更しました:

 DatabaseCleaner[:active_record].strategy = :transaction

しかし、これはローリング データベースではありません。

私のdatabase.rbは次のとおりです。

require 'active_record'
require 'database_cleaner'
require 'database_cleaner/cucumber'

ActiveRecord::Base.establish_connection(
    :adapter => 'mysql2',
    :database => 'aq_test',
    :username => 'root',
    :password => 'manager'  )

class ActiveRecord::Base
    mattr_accessor :shared_connection
    @@shared_connection = nil

    def self.connection
        @@shared_connection || retrieve_connection
    end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
DatabaseCleaner[:active_record].strategy = :transaction

ただし、これはデータベースのロールバックでもありません 注: テストケースで実行された最後のトランザクションのみをロールバックしたい

私の英語でごめんなさい

4

1 に答える 1

0

database_cleaner github ページには、そのコードをfeatures/support/database_cleaner.rbファイルに入れるように書かれています。

begin
  require 'database_cleaner'
  require 'database_cleaner/cucumber'

  DatabaseCleaner.strategy = :truncation
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Before do
  DatabaseCleaner.start
end

After do |scenario|
  DatabaseCleaner.clean
end
于 2013-02-04T13:36:44.663 に答える