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? 
On Fri, May 7, 2010 at 4:39 PM, Fearless F. [email protected]
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 | gregdonald.com
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
On May 7, 11:09 pm, Fearless F. [email protected] 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