Your understanding is slightly off. After every test case, the database is
wiped clean and then reloaded with your fixtures. So applying those fixtures
at the beginning causes that to happen for every test. That means you could
flatten the database in the first test you executed and still have the two
entries in the database for the next test.
The tests you''ve written seem to test the test behavior, which
doesn''t seem
like it would be that useful. Instead, test your code. :)
On 9/3/05, Luke Redpath
<luke-lJ1peEkt3K8wCQPON/xxHQmknBWnwzYrtUK59QYPAWc@public.gmane.org>
wrote:>
> Hi,
>
> I''m trying to run my unit tests but my fixture data isn''t
being cleared
> out for
> each TestCase, which is what I thought was meant to happen, to make sure
> the
> tests aren''t dependent on other test cases.
>
> For example, I have two models, NewsArticle and NewsCategory.
>
> The NewsArticleTest is:
>
> class NewsArticleTest < Test::Unit::TestCase
> fixtures :news_articles
>
> def setup
> <at>news_article = NewsArticle.find(1)
> end
>
> def test_test
> # nothing here yet
> end
> end
>
> As you can see all I''ve got in there for now is an empty test
method to
> avoid
> errors. I have two fixtures in my news_articles.yml fixtures file. Now, my
> understanding is that once this test case is finished, all of the fixtures
> are
> wiped out of the database, but this doesn''t seem to be happening,
as shown
> in my
> next test case:
>
> class NewsCategoryTest < Test::Unit::TestCase
> fixtures :news_categories
>
> def setup
> @news_category = NewsCategory.find(1)
> end
>
> def test_database_is_flattened
> assert_equal 0, NewsArticle.find(:all).length
> end
> end
>
> However that leaves me with:
>
> 1) Failure:
> test_database_is_flattened(NewsCategoryTest)
> [./test/unit/news_category_test.rb:11]:
> <0> expected but was
> <2>.
>
> So why are my fixtures still in there? I''m using PostgreSQL 8 on
Ubuntu.
>
> Also, has anybody ran into problems with foreign key constraints and unit
> tests
> - I was getting errors all over the place because fixtures weren''t
being
> loaded
> in the correct order so I just ended up removing my foreign key
> constraints - it
> was that or no tests.
>
> --
> Kind regards,
>
> Luke Redpath
> lastfield Limited webTeam, Birmingham Region
>
> luke-lJ1peEkt3K8wCQPON/xxHQmknBWnwzYrtUK59QYPAWc@public.gmane.org
>
> Need to urgently update to your web site? We''re available 24 hours
a day
> to assist:
>
> Telephone -- 0870 742 0662 or email
webteam-lJ1peEkt3K8wCQPON/xxHQmknBWnwzYrpaRaMNLIuro@public.gmane.org
>
> www.lastfield.com <http://www.lastfield.com>
>
> Birmingham office: 48 Hargreaves Street, Stow Heath, Wolverhampton, West
> Midlands, WV1 2TB
>
> ***
>
> lastfield Limited, Hebe House, 55 Cumnor Road, Sutton, Surrey, SM2 5DW
>
> The contents of this e-mail and any attachment(s) are strictly
> confidential and
> are solely for the person(s) at the e-mail address(es) above. If you are
> not an
> addressee, you may not disclose, distribute, copy or use this e-mail, and
> we
> request that you send an email to
postmaster-cBURFGMgNrD2eFz/2MeuCQ@public.gmane.org and delete this
> e-mail. lastfield Limited accepts no legal liability for the contents of
> this
> e-mail including any errors, interception or interference, as internet
> communications may not be secure. Whilst lastfield Limited and the sender
> have
> taken every precaution to prevent transmission of computer viruses, should
> this
> inadvertently occur we do not accept any liability.
>
>
>
--------------------------------------------------------------------------------
> If you have a matter to discuss with lastfield Limited with regards to our
> email, please contact us at
postmaster-cBURFGMgNrCzBvABCwad6g@public.gmane.org
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails