# Strange unit test failure

**URL:** <https://www.ruby-forum.com/t/strange-unit-test-failure/115821>\
**Category:** Rails\
**Created:** [September 28, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/strange-unit-test-failure/115821 "2007-09-28T20:20:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sp00nyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sp00nyg](https://www.ruby-forum.com/u/sp00nyg)\
**Post date:** [September 28, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/strange-unit-test-failure/115821/1 "2007-09-28T20:20:55Z")

</div>

I have two unit tests that works fine if I run them individually.

ex: ruby test/unit/company\_test.rb  
Loaded suite test/unit/company\_test  
Started  
…  
Finished in 0.037888 seconds.

3 tests, 7 assertions, 0 failures, 0 errors

However, if I run ‘rake test:units’ the same test as above fails with:

1. Failure:  
test\_state(CompanyTest) [./test/unit/company\_test.rb:26]:  
 is not true.

My test is:  
def test\_state  
# …  
company = companies(:test\_company)  
assert company.valid?  
end

Why would it work from ruby and not rake? I have one other test that  
fails the same way.

---

<div class="post-metadata">

**Author:** ![sp00nyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sp00nyg](https://www.ruby-forum.com/u/sp00nyg)\
**Post date:** [September 28, 2007, 8:37pm UTC](https://www.ruby-forum.com/t/strange-unit-test-failure/115821/2 "2007-09-28T20:37:56Z")

</div>

Check what fixtures are being included in the tests. I’ve run into a lot  
of  
the same problems as this, and it’s always been that I wasn’t including  
a  
fixture properly.

Jason

---

<div class="post-metadata">

**Author:** ![sp00nyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sp00nyg](https://www.ruby-forum.com/u/sp00nyg)\
**Post date:** [September 29, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/strange-unit-test-failure/115821/3 "2007-09-29T14:13:18Z")

</div>

Thanks. The issue seemed to be with one of the validations. I was  
validating against a table of states using the two letter state abbr.  
as a FK. When I took that validation out, the test worked in both  
instances. In both cases, I loaded the fixture containing all the  
state data. Feels to me like there might be a bug lurking in here  
somewhere because the test should have worked in both cases.
