Daniel Abrahamsson
2011-Sep-20 10:24 UTC
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 end end In my second test case, DealerTest, I do not want to use the car fixtures, 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 end end Now, if I run this test individually, it works fine. But if I run it using *rake test:units*, it fails. The car fixtures are left over from the previous test. Is this how it is supposed to work? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/gYDJXe-hj2sJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Sep-20 13:25 UTC
Re: What is the correct behaviour when manually specifying which fixtures to load?
On 20 September 2011 11:24, Daniel Abrahamsson <hamsson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > end > end > In my second test case, DealerTest, I do not want to use the car fixtures, > 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 > end > end > Now, if I run this test individually, it works fine. But if I run it using > rake test:units, it fails. The car fixtures are left over from the previous > test. > 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. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.