# Unit tests breaks with sqlite

**URL:** <https://www.ruby-forum.com/t/unit-tests-breaks-with-sqlite/105775>\
**Category:** Rails\
**Created:** [June 2, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/unit-tests-breaks-with-sqlite/105775 "2007-06-02T16:18:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [June 2, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/unit-tests-breaks-with-sqlite/105775/1 "2007-06-02T16:18:51Z")

</div>

Hi,

I’m using an sqlite3 database with Rails and have some trouble running  
unit tests

What I’ve done is

- rails my\_app

- edited database.yml to use sqlite3 adapter, db/my\_app\_development  
and db/my\_app\_test

- ruby script\generate model user

- edited model

- edited db/migrate/001\_create\_users.rb migration:

- and:

- rake db:migrate

- rake db:test:prepare

At this point, the 2 DBs are created correctly.

- rake test:units

The problem is that, but when I want to run a (any) test, I get a "SQL  
logic error or missing database (SQLite3::SQLException). I can however  
access the DB via the sqlite3 client/rails console without any  
problem.

Here’s the exact error message I get:

Loaded suite C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/  
lib/rake/rake\_test\_loader  
Started  
EC:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1-  
mswin32/lib/sqlite3/errors.rb:94:in `check': SQL logic error or missing database (SQLite3::SQLException) from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3- ruby-1.2.1-mswin32/lib/sqlite3/resultset.rb:76:in`check’  
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3-  
ruby-1.2.1-mswin32/lib/sqlite3/resultset.rb:68:in `commence' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3- ruby-1.2.1-mswin32/lib/sqlite3/resultset.rb:61:in`initialize’  
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3-  
ruby-1.2.1-mswin32/lib/sqlite3/statement.rb:163:in `new' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3- ruby-1.2.1-mswin32/lib/sqlite3/statement.rb:163:in`execute’  
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3-  
ruby-1.2.1-mswin32/lib/sqlite3/database.rb:212:in `execute' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3- ruby-1.2.1-mswin32/lib/sqlite3/database.rb:187:in`prepare’  
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/sqlite3-  
ruby-1.2.1-mswin32/lib/sqlite3/database.rb:211:in `execute' ... 16 levels... from C:/InstantRails/ruby/lib/ruby/1.8/test/unit/autorunner.rb: 200:in`run’  
from C:/InstantRails/ruby/lib/ruby/1.8/test/unit/autorunner.rb:  
13:in `run’  
from C:/InstantRails/ruby/lib/ruby/1.8/test/unit.rb:278  
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/  
lib/rake/rake\_test\_loader.rb:5

I’m using Rails 1.2.3 with ruby 1.8.5, sqlite3.3.7 and sqlite3-ruby  
(1.2.1)  
Any help would be greatly appreciated!

Thanks in advance,

Frédéric Delanoy

---

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [June 2, 2007, 6:34pm UTC](https://www.ruby-forum.com/t/unit-tests-breaks-with-sqlite/105775/2 "2007-06-02T18:34:15Z")

</div>

I’ve seen that “logic error” where there was a COMMIT or ROLLBACK, but  
no transaction was in flight. This is an Exception (not an Error), and  
Test::Unit doesn’t catch them, unfortunately.

Somewhere within this line:  
… 16 levels…  
is your unit test code.

To debug it, modify something like execute in sqlite3/database.rb to  
do the following:

rescue Exception =\> e  
puts e.message  
puts e.backtrace  
raise  
end

so that you can see those “16 levels”.

Alex

---

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [June 3, 2007, 9:19am UTC](https://www.ruby-forum.com/t/unit-tests-breaks-with-sqlite/105775/3 "2007-06-03T09:19:23Z")

</div>

I’ve finally found the source of the problem: it was due to the  
default fixtures in use, i.e.

first  
id: 1  
second  
id: 2

After adding a (mandatory in my model) name attribute in the fixture,  
like  
first  
id: 1  
name: foo  
second  
id:2  
name: bar

it worked.

However, what’s odd is that evenif I commented the line  
fixtures :users  
in the unit test file, I had the some error.

Maybe the fixtures are used automagically ???

In all cases, thank you for your help Alexey !

Frédéric

On 2 juin, 18:33, “Alexey V.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
