Why are my unit tests passing?

Most people want to know why their tests are failing. I want to know
why they are passing. They really shouldn’t be.

The test environment database defined in database.yml does not exist.
I have not altered the auto-generated tests at all. When I run the
following command from the site root:

ruby test/unit/gender_test.rb

I expect that this should fail. However, I get

“1 tests, 1 assertions, 0 failures, 0 errors”

I’m working my way through the Prag Prog Agile Rails book. In the
testing section (page 186), the book says that these tests should fail
until I create the testing database. Is the book wrong, or do I have
magic unit tests?

RoR Version: 1.2.3
Ruby Version: 1.8.6
DB: Mysql

Thanks for the help.

Ian

Ian wrote:

Most people want to know why their tests are failing. I want to know
why they are passing. They really shouldn’t be.

The test environment database defined in database.yml does not exist.
I have not altered the auto-generated tests at all. When I run the
following command from the site root:

ruby test/unit/gender_test.rb

I expect that this should fail. However, I get

“1 tests, 1 assertions, 0 failures, 0 errors”

I’m working my way through the Prag Prog Agile Rails book. In the
testing section (page 186), the book says that these tests should fail
until I create the testing database. Is the book wrong, or do I have
magic unit tests?

RoR Version: 1.2.3
Ruby Version: 1.8.6
DB: Mysql

Thanks for the help.

Ian

Ian,

By default the test case that is provided by the generator for each
model is assert_truth() which returns true so initially “all” test cases
pass.

Thank you for your reply.

I noticed the simplicity of the default test & have some familiarity
with both unit testing and Test::Unit. But the example I’m reading
says that even this very simple test should fail if the database
doesn’t exist. That’s where my confusion comes from.

On Dec 4, 1:33 pm, Ilan B. [email protected]

Ian,

I noticed the simplicity of the default test & have some familiarity
with both unit testing and Test::Unit. But the example I’m reading
says that even this very simple test should fail if the database
doesn’t exist. That’s where my confusion comes from.

Do you have any fixtures declared in your tests? If not, then Rails
might not be bothering to connect to the database at all.

Jim

Jim M., [email protected], [email protected]
http://www.io.com/~jimm/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs