# Testing Issue

**URL:** <https://www.ruby-forum.com/t/testing-issue/109955>\
**Category:** Rails\
**Created:** [July 20, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/testing-issue/109955 "2007-07-20T17:28:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![visaolive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@visaolive](https://www.ruby-forum.com/u/visaolive)\
**Post date:** [July 20, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/testing-issue/109955/1 "2007-07-20T17:28:33Z")

</div>

I have a weird (at least for me) problem.

$rake test

Units: 50 tests, 155 assertions, 0 failures, 0 errors  
Functionals: 51 tests, 122 assertions, 0 failures, 0 errors  
Integration: 1 tests, 19 assertions, 0 failures, 0 errors

$rake test:functionals

51 tests, 109 assertions, 3 failures, 0 errors

$ruby test/functional/registrations\_controller\_test.rb

20 tests, 59 assertions, 3 failures, 0 errors

Why rake test passes everything ok and the other fails?

---

<div class="post-metadata">

**Author:** ![visaolive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@visaolive](https://www.ruby-forum.com/u/visaolive)\
**Post date:** [July 20, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/testing-issue/109955/2 "2007-07-20T17:36:33Z")

</div>

I imagine this could have something to do with test data. Check that  
all the require fixtures are included in your controller test. The  
data may be being loaded in other tests - hence the passes when you  
run the whole suite.

Steve

---

<div class="post-metadata">

**Author:** ![visaolive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@visaolive](https://www.ruby-forum.com/u/visaolive)\
**Post date:** [July 20, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/testing-issue/109955/3 "2007-07-20T17:42:34Z")

</div>

On 7/20/07, Steve B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I imagine this could have something to do with test data. Check that  
> all the require fixtures are included in your controller test. The  
> data may be being loaded in other tests - hence the passes when you  
> run the whole suite.

Now something weirder happens:

$rake test

# everything OK

$ruby test/functional/registrations\_controller\_test.rb

# everything OK

$rake test:functionals

# 3 failures

$ruby test/functional/registrations\_controller\_test.rb

# 3 failures LOL

It’s a cache issue or what is happening here? i think its more like a  
bug…

---

<div class="post-metadata">

**Author:** ![visaolive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@visaolive](https://www.ruby-forum.com/u/visaolive)\
**Post date:** [July 20, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/testing-issue/109955/4 "2007-07-20T17:52:36Z")

</div>

On 7/20/07, Emilio T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> $rake test
> 
> $ruby test/functional/registrations\_controller\_test.rb
> 
> # 3 failures LOL
> 
> It’s a cache issue or what is happening here? i think its more like a bug…

I solved the problem adding missing fixtures as Steve told me, but  
hey! wait a second!, this means that i always have to test my  
functional tests after doing a ““complete”” test?

My conclusion is that some fixtures gets cached somewhere after  
running my unit tests, that shouldn’t happen.

Is this meant to be this way or it’s a bug?

---

<div class="post-metadata">

**Author:** ![visaolive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@visaolive](https://www.ruby-forum.com/u/visaolive)\
**Post date:** [July 20, 2007, 6:08pm UTC](https://www.ruby-forum.com/t/testing-issue/109955/5 "2007-07-20T18:08:40Z")

</div>

On Jul 20, 2007, at 11:28 AM, Emilio T. wrote:

> 51 tests, 109 assertions, 3 failures, 0 errors
> 
> $ruby test/functional/registrations\_controller\_test.rb
> 
> 20 tests, 59 assertions, 3 failures, 0 errors
> 
> Why rake test passes everything ok and the other fails?

You are likely using fixtures, right? If you look at the fixtures  
loaded for your RegistrationsControllerTest, be sure that all the  
fixture expectations are listed in that file. I’ve run into this  
very problem before. There are some who will recommend all fixtures  
be listed in the test\_helper.rb, but I think that’s just an excuse  
not to stop and think about which fixtures you really _need_ for a test.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![visaolive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@visaolive](https://www.ruby-forum.com/u/visaolive)\
**Post date:** [July 20, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/testing-issue/109955/6 "2007-07-20T21:26:01Z")

</div>

Emilio T. wrote:

> > $ruby test/functional/registrations\_controller\_test.rb

next, try:

$ruby test/functional/registrations\_controller\_test.rb -n  
test\_one\_specific\_test

> I solved the problem adding missing fixtures as Steve told me, but  
> hey! wait a second!, this means that i always have to test my  
> functional tests after doing a ““complete”” test?

I interpret this to mean “each time I change any test, must I run all  
the tests independently to verify they isolate correctly?”

The general answer is no - testing the tests is the road to madness.  
Your production code never had a bug here, and tests should fail  
_more\_easily_ than production code gets bugs.

However, yes, each time you add a fixture to a test case you risk  
breaking test isolation with other test cases. A good way to catch  
this is test with rake test:recent or rake test:svn\_modified, each  
time you change the code. That way, as you change different  
combinations of test cases, you get to see if they (apparently)  
isolate from each other, independent of the group. Many a Rails  
application can no longer run a partial test because only the total  
test worked when they integrated.

> My conclusion is that some fixtures gets cached somewhere after  
> running my unit tests, that shouldn’t happen.

Yes, in the database. (-;

> Is this meant to be this way or it’s a bug?

You are lucky to have test fixtures. Some systems make them so slow,  
their programmers must avoid database calls in most tests! So any  
residual optimizations here are generally to your benefit. Perfect  
test isolation would restart and rebuild the database between each  
test run. We rely on less than perfect isolation in exchange for  
speed.

–  
Phlip  
[http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
