Specs run individually pass, but fail on rake spec?

When I run specs individually: ruby /path/to/spec.rb it will pass. However, its more likely to fail when I run rake spec

Does anyone know why that is, am I doing something wrong?

TIA, Luke

We had trouble like that, when for example we had forgotten to declare fixtures in a file where we used them. In this case it can happen, that the test runs, if the fixture was loaded before in another file, but failed in other cases, depending on how the test was started.

Also, if your test db gets full of dirty data (data from pasts tests that was not deleted) then the order which you run your tests might affect the outcome. Always be sure to delete all data that you save in your tests, especially when dealing with models that have validates_uniqueness_of :...

before :each do    Model.delete_all    JoinModels.delete_all    Other.delete_all end

Also, if your test db gets full of dirty data (data from pasts tests that was not deleted) then the order which you run your tests might affect the outcome. Always be sure to delete all data that you save in your tests, especially when dealing with models that have validates_uniqueness_of :...

before :each do   Model.delete_all   JoinModels.delete_all   Other.delete_all end

I don't know much about rspec, but if it's at least vaguely sensible
it will be doing the same thing as the rails test::unit stuff which
wraps tests in a transaction so that you don't need cleanup like that
(although this will of course break if you break the transaction (eg
by using MyISAM tables in mysql) or executing a statement that causes
an implicit commit. More generally anything that makes a state change that is not rolled
back can cause this sort of failure (eg changing class variables)

Fred