sydneyos wrote:> The database is blown out BEFORE the tests are run, not during or
> after, near as I can tell; I personally am using fixtures, which end
> up causing records to be inserted in the db, and they remain there
> after the tests are run, unchanged by the tests.
The tests run inside a big transaction.
How can you write a test, unless you know what the database is going to
look like at the time it gets run?
An example is this;
You have two tests.
def test_delete_everything
# we''ve put fixtures in place, so there is something to delete
assert_operator 0, :<, Model.count
Model.delete_everything
assert_equal 0, Model.count
end
def test_make_a_whole_load_of_stuff
# we know there are 5 models in the fixtures
# so lets just assert that there is something in here before hand
count_before = Model.count
assert_operator 0, :<, count_before
# a whole load of stuff is actually just 3 new models
Model.make_a_whole_load_of_stuff
assert_equal count_before + 3, Model.count
end
If the delete test gets run first, our database will be empty, and break
the 2nd test,
if it gets run second then it''ll pass.
So, instead, the transaction ensures that the database starts and ends
in the same state. And that state is expected to be just the fixtures
you define for it.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---