Rails Tip : 1 Place To Define Fixtures
This wasn't immediately obvious to me until recently.
You don't need to repeat your list of fixtures in every unit test file. Put your fixture list in the test_helper.rb file. Look for the line that says this, "# Add more helper methods to be used by all tests here..." Put your fixture list right after that, before the "end". So it looks like this:
class Test::Unit::TestCase
# Omitted rest of code in class
# Add more helper methods to be used by all tests here...
fixtures :model1, :model2, :model3
end
You don't need to repeat your list of fixtures in every unit test file. Put your fixture list in the test_helper.rb file. Look for the line that says this, "# Add more helper methods to be used by all tests here..." Put your fixture list right after that, before the "end". So it looks like this:
class Test::Unit::TestCase
# Omitted rest of code in class
# Add more helper methods to be used by all tests here...
fixtures :model1, :model2, :model3
end


4 Comments:
Nice tip, thanks.
No problem. You're my inspiration for these bit-sized Rails tips!
Ha ha! We'll have to see who can come up with the shortest tip! It think my latest one is pretty concise.
BTW, have you seen this: http://peepcode.com/? Excellent idea.
That is concise!
That peepcode thing looks cool, but I don't want to drop the $9 on it. Maybe if someone else highly recommends it. (I've been meaning to get up to speed with RJS. My app was started before RJS was around, so I'm kick'n it Rails 1.0 style.)
Post a Comment
<< Home