# Inconsistent test results

**URL:** <https://www.ruby-forum.com/t/inconsistent-test-results/78520>\
**Category:** Rails\
**Created:** [December 6, 2006, 3:07pm UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520 "2006-12-06T15:07:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [December 6, 2006, 3:07pm UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520/1 "2006-12-06T15:07:37Z")

</div>

Hello All,  
I seem to be having recurring problems in that my tests work in some  
cases, and not in others.

My OS is Ubuntu 6.10 - the Edgy Eft and I’m using:

RadRails 0.7.1  
Ruby 1.8.4  
MySQL 5.0.24a-Debian\_9-log  
Rails 1.1.6

To give an example yesterday I had an issue where a particular unit  
test was failing when run as part of a group of unit tests. However,  
running this test alone passed.

Furthermore, today I have a situation where my an assert\_tag in my  
functional tests is failing from the command line

rake test:functionals

However running the functional tests from RadRails is working. Is  
anyone else experiencing inconsistent behaviour like this? I find  
myself spending most of the time trying to resolve these issues rather  
than building functionality. This is causing me huge frustration so any  
assistance would be greatly appreciated.

Regards,  
John

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [December 6, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520/2 "2006-12-06T18:11:14Z")

</div>

JohnW wrote:

> To give an example yesterday I had an issue where a particular unit  
> test was failing when run as part of a group of unit tests. However,  
> running this test alone passed.

Most likely you have inter suite dependency problems. You need to make  
sure that all testcases have the needed fixtures instead of accidentally  
reusing garbage. If using transactional fixtures, check by looking at  
log/test.log that “BEGIN” “ROLLBACK” are called before the test code  
itself. You can also disable transactional fixtures for selected suites.

Zsombor

–  
Company - [http://primalgrasp.com](http://primalgrasp.com)  
Thoughts - [http://deezsombor.blogspot.com](http://deezsombor.blogspot.com)

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [December 6, 2006, 10:32pm UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520/3 "2006-12-06T22:32:30Z")

</div>

Hi Zsombor,  
I have transactions turned on in test\_helper.

Can you tell me how to disable transactional fixtures for selected  
suites?  
I’d like to try that and see the results?

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [December 7, 2006, 6:41am UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520/4 "2006-12-07T06:41:32Z")

</div>

There is a known bug in Rails when the assert\_tag is used in the  
integration tests

Check out Mark Lunds website for more information:  
[http://wiki.marklunds.com/index.php?title=Test\_Driven\_Development\_with\_Ruby](http://wiki.marklunds.com/index.php?title=Test_Driven_Development_with_Ruby)

To fix this replace the old html\_document method in test\_process.rb  
with the following:

```
def html_document
  HTML::Document.new(@response.body)
end

```

Give it a shot and let us know if that solves your problem.

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [December 7, 2006, 12:30am UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520/5 "2006-12-07T00:30:56Z")

</div>

John W. wrote:

> Can you tell me how to disable transactional fixtures for selected  
> suites? I’d like to try that and see the results?

Basically you just set the use\_transactional\_fixtures class level  
variable  
to false. For example to disable for one particular suite:

> class SlowGroupsControllerTest \< Test::Unit::TestCase  
> fixtures :groups, :users
> 
> # turn transactions off since we have atleast one transaction
> 
> # dependent testcase. With mysql transactions cannot be nested.
> 
> self.use\_transactional\_fixtures = false  
> #…
> 
> # your tests here
> 
> #…  
> end

## Best, Zsombor

Company - [http://primalgrasp.com](http://primalgrasp.com)  
Thoughts - [http://deezsombor.blogspot.com](http://deezsombor.blogspot.com)

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [December 7, 2006, 3:02pm UTC](https://www.ruby-forum.com/t/inconsistent-test-results/78520/6 "2006-12-07T15:02:54Z")

</div>

Hi All,  
Thanks for your replies. My issues were because of a combination of  
problems, and really only identified by isolating the issues by taking  
the  
following actions.

1. Turn off transactional fixtures
2. Running tests individually using ruby test/…/my\_test.rb --name  
test\_my\_method

When the test failed I was able to integrate the database and see its  
state,  
which helped me establish the core problem.

Another issue I had was with caching in my functional tests. For  
instance

def test\_something  
bill = users(:bill)

#suppose User has a has\_one :email

#do some functional testing to remove email  
…

#check bill  
assert\_nil bill.email

end

In the above the bill.email has failing, though the related record had  
been  
deleted.

The following reloads the association and works

assert\_nil bill.email(true)

Regards,  
John
