On Fri, Dec 2, 2016 at 11:57 AM, 'krfg' via Ruby on Rails: Talk
<rubyonrails-talk@googlegroups.com> wrote:
> Some of my tests would not pass if the test database was not cleared after
> the previous tests.
The important thing is that every test start from a *known state*.
The easiest state to achieve and reason about, is empty. It also
forces you to be more explicit within your tests (or their
setup/before blocks) about any records you're adding in support of the
test.
But, if you want to start from a known *populated* state, that's a
pretty common approach too.
Either way, though, you need to clean up any changes each test makes.
With a populated start state, you can do each test in a transaction
and roll it back, which assumes you're using a DBMS that supports
that. With an empty state, you can do that, *or* truncate the tables,
or various other options.
-Dave
--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQijfoxdJ-CkEL7ZkZVpZHLy%2B7Z8wbKuC5_i6ZctMBMCjLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment