# Test suite assertion: 0 == 1 is true?

**URL:** <https://www.ruby-forum.com/t/test-suite-assertion-0-1-is-true/188225>\
**Category:** Rails\
**Created:** [May 7, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/test-suite-assertion-0-1-is-true/188225 "2010-05-07T23:39:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [May 7, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/test-suite-assertion-0-1-is-true/188225/1 "2010-05-07T23:39:02Z")

</div>

I must be missing something fundamental. In the test code below, the  
assertion should fail unless WebPageCache.count == 1. But  
WebPageCache.count is zero (according to the print statement and all  
other evidence), yet the assertion passes.

# What am I missing?

# class WebPageCacheTest \< ActiveSupport::TestCase … test “table has one entry” do p “\<\<\< #{WebPageCache.count}” # prints ‘\<\<\< 0’ assert (WebPageCache.count == 1), “WebPageCache size is not 1” end … end

(An aside: if I can’t trust a simple assert, what CAN I trust? 🙂

- ff

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [May 7, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/test-suite-assertion-0-1-is-true/188225/2 "2010-05-07T23:44:33Z")

</div>

On Fri, May 7, 2010 at 4:39 PM, Fearless F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I must be missing something fundamental. In the test code below, the  
> assertion should fail unless WebPageCache.count == 1.

> assert (WebPageCache.count == 1), “WebPageCache size is not 1”

Did you try WebPageCache.count.to\_i == 1 or WebPageCache.count == ‘1’ ?

–  
Greg D.  
[destiney.com](http://destiney.com) | [gregdonald.com](http://gregdonald.com)

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [May 8, 2010, 12:09am UTC](https://www.ruby-forum.com/t/test-suite-assertion-0-1-is-true/188225/3 "2010-05-08T00:09:55Z")

</div>

Greg D. wrote:

> Did you try WebPageCache.count.to\_i == 1 or WebPageCache.count == ‘1’ ?

For grins, yes. No change.

But I’m beginning to guess: are the db tables rolled back between EVERY  
call to test? I thought they were rolled back at the end of the test  
run, not between every test.

Asked another way: if web\_page\_caches starts as empty, what are the  
expected results in the following?

======  
class WebPageCacheTest \< ActiveSupport::TestCase  
test “store an entry” do  
WebPageCache.store(“my\_key”, “my\_value”)  
assert (WebPageCache.count == 1), “WebPageCache size is not 1”

# test “table still has one entry” do assert (WebPageCache.count == 1), “WebPageCache size is not 1” end end

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [May 8, 2010, 11:24am UTC](https://www.ruby-forum.com/t/test-suite-assertion-0-1-is-true/188225/4 "2010-05-08T11:24:33Z")

</div>

On May 7, 11:09 pm, Fearless F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Greg D. wrote:
> 
> > Did you try WebPageCache.count.to\_i == 1 or WebPageCache.count == ‘1’ ?
> 
> For grins, yes. No change.
> 
> But I’m beginning to guess: are the db tables rolled back between EVERY  
> call to test? I thought they were rolled back at the end of the test  
> run, not between every test.

between every test (or rather each test runs inside a transaction  
which is rolled back). There should be no leakage of state from one  
test to another.

Fred
