What is the correct behaviour when manually specifying which fixtures to load?

I have a problem with fixtures not being removed between tests and would
like to know if this is expected behavior or not.

For example, say that I have a model Car, and a car.yml fixtures file. I
have two test cases CarTest and DealerTest. In the first test,
I want to use fixtures, so I define it like this:

class CarTest< ActiveSupport::TestCase
fixtures :cars

test “Car fixtures should have been loaded” do
assert_equal NUMBER_OF_FIXTURES, Car.count

In my second test case, DealerTest, I do not want to use the car
but want to create some of my own.
class DealerTest< ActiveSupport::TestCase

test “No Cars should be in the database” do
assert_equal 0, Car.count

Now, if I run this test individually, it works fine. But if I run it
using rake
, it fails. The car fixtures are left over from the previous

Is this how it is supposed to work?

On 20 September 2011 11:24, Daniel A. [email protected]

rake test:units, it fails.The car fixtures are left over from the previous
Is this how it is supposed to work?

I think you are misinterpreting the symptom. I think it is not that
the fixtures are left over from the previous test, but that when using
rake test it forces all fixtures to be reloaded for each test. If I
am right then the question is “how to stop rake test from loading
fixtures”. I do not know the answer however. I stopped using
fixtures some time ago, I think the consensus is that fixtures are a
Bad Thing and that factories are the way to go. I tend to agree.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs