Here?s the bottom line: even if a test method updates the test database,
the database is put back to its default state before the next test
method is
run. This is important because we don?t want tests to become dependent
on the results of previous tests.
Well, I’ve been running into a brick wall with some functional tests
based off of what the scaffold generator created for me.
assert_raise(ActiveRecord::RecordNotFound) {
Article.find(1)
}
end
And finally, the error that’s being thrown when this is run:
Error:
test_edit(Controllers::Admin::ArticlesControllerTest):
ActiveRecord::RecordNotFound: Couldn’t find Article with ID=1
So, it looks like test_destroy is being run first… any idea why my
fixtures aren’t being reloaded before each test is being run? Is there
something else I should be doing?
So, it looks like test_destroy is being run first…
Yup… They’re run in alphabetical order.
any idea why my
fixtures aren’t being reloaded before each test is being run? Is there
something else I should be doing?
Silly question, but let’s get it out of the way: Do you have a
fixtures :articles
line in your testcase? If it’s come direct from the scaffold, it should
be there, but just in case…
If they weren’t loaded at all, that would have the same effect.
Silly question, but let’s get it out of the way: Do you have a
fixtures :articles
line in your testcase? If it’s come direct from the scaffold, it
should be there, but just in case…
Yep,
fixtures :articles, :article_versions
to be exact. Odd enough, when I run the test_edit directly:
$ ruby articles_controller_test.rb -n test_edit
it runs fine.
If they weren’t loaded at all, that would have the same effect.
Oh, and what’s your database and version?
MySQL 4.1.16 and I’m using the mysql gem.
Another problem to note is when writing my tests my fixtures aren’t
available directly in my test cases:
first:
id: 1
published: 1
publish_on: 2006-01-24 14:50:30
And if I try to use @first in the test, it comes back as nil. Could the
problems be related?