在我的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"
我正在使用gem:
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没有回滚我的数据库记录为什么?我错过了什么吗?