Closed artemave closed 11 years ago
The main reason I don't do that is to prevent test pollution.
But perhaps there could be an option to with_model
and with_table
that creates the table in before(:all)
and tears it down after(:all)
.
If we were to keep the table between tests, would you expect that the table is empty at the beginning of each spec? How should it be emptied? Or should that be up to some other tool like DatabaseCleaner?
The options I can think of are:
TRUNCATE
the table in before(:each)
.DELETE FROM
the table in before(:each)
.I prefer 4 because it would match how other tables work.
Tests for existing models do not recreate schema between every test and it does not seem to cause pollution. I don't see why it would in case of with_model
.
As for data cleansing, rspec wraps each example in transaction (or whatever user preference, such as DatabaseCleaner) so I wouldn't be surprised if it would just work out of the box in case of with_model
before(:all). If not, tapping into rspec own cleansing behaviour somehow would seem to me like the best option.
At the moment, it seems to create table on every example (unless I am missing something).
It would be nice to have an option to do it once per with_table declaration, purely to make it faster.
Otherwise, thank you very much for a great gem. I also quite like how it adds the documentation aspect to the spec. Like here for instance:
with_model
block shows what the table should have in order to use this custom validation and how to use it. Me like!