[rspec-users] pontential bug in rspec_on_rails and ActiveRecord transactions

Tilmann Singer tils-rspec at tils.net
Wed Apr 4 14:03:46 EDT 2007

* Esad Hajdarevic <esad at esse.at> [20070404 18:57]:
> The log output was:
>   DELETE FROM contacts
>   DELETE FROM urls
>   INSERT INTO urls (`icon_url`, `domain`, `url`, `cached_version`, 
> `description`, `created_at`) VALUES(NULL, NULL, 
> 'http://www.example.com/', 0, NULL, '2007-04-04 15:35:46')
>   INSERT INTO contacts (`internal_id`, `name`, `updated_at`, 
> `primary_email`, `notes`, `user_id`, `created_at`) VALUES(NULL, NULL, 
> '2007-04-04 15:35:46', 'user at example.com', NULL, NULL, '2007-04-04 
> 15:35:46')
>   SELECT count(*) AS count_all FROM urls
> How did count statement got into transaction? Is rspec doing some
> magic with ActiveRecord that is causing this to happen?

RSpec does the same as the Test::Unit framework, it will wrap each
test run in a transaction and roll it back at the end, if the

use_transactional_fixtures = true

is set (in spec_helper.rb). If you want to test behaviour that is
depending on db transactions then I think it is necessary to set this
to false.


More information about the rspec-users mailing list