开发者

Rails how to clear database between selenium tests

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜