Search code examples
ruby-on-railsdebuggingrspecfactory-botguard

Is there any way to inspect DB data when running FactoryGirl?


Setup: Hi, I have Rails 3.2, Guard, RSpec and FactoryGirl. Pretty common.

The Problem: The user I created as admin doesn't behave as expected. Also, when the tests are finished, the database is already empty, so I can't understand what's happening.

Desired: I'd like to "debug", or - in other words - to have some breakpoint and inspect my_test database.

- OR - At least I'd like to DB to be cleaned in the beginning of tests, not at the end.

Many thanks.


Solution

  • Install the debugger gem and you'll be able to drop into the debugger by calling debugger

    Tests are wrapped in a transaction and on most (all?) databases this means that other connections (for example the one opened by whatever database browsing tool you use) can't see the changes made by your test. You can change this on mysql with

    set transaction isolation level read uncommitted
    

    Other databases may vary