ruby - Difference between truncation, transaction and deletion database strategies -
what difference between truncation, transaction , deletion database strategies when using rspec? can't find resources explaining this. read database cleaner readme doesn't explain each of these do.
why have use truncation strategy capybara? have clean database when testing or can disable it. dont understand why should clean database after each test case, wouldn't slow down testing?
the database cleaning strategies refer database terminology. i.e. terms come (sql) database world, people familiar database terminology know mean.
the examples below refer sql definitions. databasecleaner supports other non-sql types of databases too, definitions same or similar.
deletion
this means database tables cleaned using sql delete from statement. slower truncation, may have other advantages instead.
truncation
this means database tables cleaned using truncate table statement. empty table immediately, without deleting table structure or deleting records individually.
transaction
this means using begin transaction statements coupled rollback roll sequence of previous database operations. think of "undo button" databases. think used cleaning method, , fastest since changes need not directly committed db.
example discussion: rspec, cucumber: best speed database clean strategy
reason truncation strategy capybara
the best explanation found in capybara docs themselves:
# transactional fixtures not work selenium tests, because capybara # uses separate server thread, transactions hidden # from. hence use databasecleaner truncate our test database. cleaning requirements
you not have clean database after each test case. need aware of side effects have. i.e. if create, modify, or delete records in 1 step, other steps affected this?
normally rspec runs transactional fixtures turned on, never notice when running rspec - keep database automatically clean you:
https://www.relishapp.com/rspec/rspec-rails/v/2-10/docs/transactions
Comments
Post a Comment