Reputation: 48438
If, as part of an RSpec or Cucumber test in my Rails application, I create a model and store it in the test database, how long will the record remain there for?
I'm pretty sure that the records are cleared at the end (or beginning?) of every test cycle, because they don't seem to interfere with successive runs of my test suite, but do records persist between different cucumber features and scenarios, or between different RSpec tests?
Upvotes: 3
Views: 547
Reputation: 47578
If you are using transactions, changes will be rolled back after each example.
If you are not using transactions, the changes will persist unless you clear them out using some other technique. This is the typical case for request specs; thus something like database_cleaner or a hand-rolled method is required to clear out the test database.
RSpec's default spec_helper file contains the line:
config.use_transactional_fixtures = true
which implies that transactions will be used.
Upvotes: 2