开发者

Rails how to clear database between selenium tests

开发者 https://www.devze.com 2023-03-18 02:21 出处:网络
Rails 3 Rspec 开发者_StackOverflow中文版Selenium webrat Selenium tests write to the development database.

Rails 3 Rspec 开发者_StackOverflow中文版Selenium webrat

Selenium tests write to the development database.

I need a way to run rake db:reset before or after each test.

Is there a way to run rake db:reset from within an integration test?


You might look at the database_cleaner gem (see the documentation at https://github.com/bmabey/database_cleaner). Once you have it installed, you could add this to your spec_helper.rb file:

Spec::Runner.configure do |config|

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

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

end
0

精彩评论

暂无评论...
验证码 换一张
取 消