1

在我的 env.rb 中

Before do
    DatabaseCleaner.strategy = :transaction
end

还在我的 shared_steps.rb 中创建了一个钩子

Before('@database_cleaner_before') do
  DatabaseCleaner.start
end

After('@database_cleaner_after') do
    DatabaseCleaner.clean
end

在我的功能文件中

@database_cleaner_after @database_cleaner_before
Scenario: I can sign up with a new valid "Email" and "Username"
      When I enter a new valid "Email"
      And I enter a new "Username"
      And I enter a "Password"
      And I click on the "Sign up" button
      Then I should see a message with word "Signed Up" and "Successfully"

我正在使用宝石:

Capybara 2.0.2
cucumber 1.2.1
database_cleaner 0.9.1
selenium-webdriver 2.30.0
cucumber-rails 1.3.0
Rails 3.1.0

在我的 database.rb 中

require 'active_record'
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.strategy = :trancation 工作正常(从数据库中删除所有记录)但 DatabaseCleaner.strategy = :transaction 没有回滚我的数据库记录,为什么?我错过了什么吗?

4

0 回答 0