# Specs run individually pass, but fail on rake spec?

**URL:** <https://www.ruby-forum.com/t/specs-run-individually-pass-but-fail-on-rake-spec/142561>\
**Category:** Rails\
**Created:** [July 9, 2008, 8:02am UTC](https://www.ruby-forum.com/t/specs-run-individually-pass-but-fail-on-rake-spec/142561 "2008-07-09T08:02:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [July 9, 2008, 8:02am UTC](https://www.ruby-forum.com/t/specs-run-individually-pass-but-fail-on-rake-spec/142561/1 "2008-07-09T08:02:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [July 9, 2008, 10:24am UTC](https://www.ruby-forum.com/t/specs-run-individually-pass-but-fail-on-rake-spec/142561/2 "2008-07-09T10:24:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [July 9, 2008, 11:11am UTC](https://www.ruby-forum.com/t/specs-run-individually-pass-but-fail-on-rake-spec/142561/3 "2008-07-09T11:11:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [July 9, 2008, 12:04pm UTC](https://www.ruby-forum.com/t/specs-run-individually-pass-but-fail-on-rake-spec/142561/4 "2008-07-09T12:04:25Z")

</div>

On 9 Jul 2008, at 10:09, Wolas! wrote:

> 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
