Unit tests - without the db?


#1

Hi

Having done TDD and unit tests in general before coming (recently) to
Ruby
and RoR, a question comes to my mind: do many people write unit tests
which
do not interact with the database ? The skeletton of unit tests
generated
automatically when creating a new model class seems to assume the common
behaviour is to test against the database rather than in memory.

Please note that I understand the benefits of testing against the
database,
but I’d like to know if it’s also a common habit when writing RoR apps
to
add non-db related unit tests for the model…

Any advice or opinion ?

cheers!

Thibaut Barrère


#2

Thibaut :

Having done TDD and unit tests in general before coming (recently)
to Ruby and RoR, a question comes to my mind: do many people
write unit tests which do not interact with the database ? The
skeletton of unit tests generated automatically when creating a
new model class seems to assume the common behaviour is to
test against the database rather than in memory.

Assuming you can use SQLite3, You can do tests against in-memory
SQLite database. Of course, it will not deal with MySQL or PostgreSQL
specific issues.

in database.yml :

test:
adapter: sqlite3
database: “:memory:”

    -- Jean-François.


À la renverse.