The README says it all:

You’re knee deep in a debugger session, and you can’t understand why something’s wrong. You wish you could fire up your application against the test database, but sadly, the process which is running the tests is within a transaction, and thus the actual data is opaque. What can you do?

1 # Somewhere deep in your tests
2 test "the frobble touches the widget" do
3   assert_equal 42, frobble.widget_id
4 end

You’ve been on this assert_equal call for the past hour wondering. Frustration’s been mounting, because you don’t understand why the frobble doesn’t touch the widget. Clearly, there’s something wrong with the fixtures, but you can’t understand what it is. Time to fire up the debugger and dump the data:

 1 [814, 823] in test/unit/widget_test.rb
 2    814!
 3    815        end
 4    816
 5    817        test "the frobble touches the widget" do
 6    818          debugger
 7 => 819          assert_equal 42, frobble.widget_id
 8    820        end
 9    821
10    822        test "the widget touched the frobble in turn" do
11    823          assert widget.touched_by_frobble?
12 test/unit/widget_test.rb:819
13 => 819          assert_equal 42, frobble.widget_id
14 (rdb:112)

Since the data_dumper gem is already declared in your Gemfile (if not, declare it, bundle install, then run your tests again), type:

1 (rdb:112) File.mkdir(Rails.root + "dump")
2 (rdb:113) DataDumper.dump(Rails.root + "dump")

Then, quit your failing tests, and from the trusty command line:

1 $ rails console
2 > DataDumper.load(Rails.root + "dump")
3 > exit
5 $ rails server

Any and all data from your test database will be loaded in your development environment. You can now explore your model with your trusty application, to find out what’s really going on.


Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend


Projects I work on

Projects I worked on